home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / libwww2 / HTAABrow.p < prev    next >
Encoding:
Text File  |  2002-03-13  |  106.6 KB  |  3,658 lines

  1.  
  2. /* MODULE                            HTAABrow.c
  3. **        BROWSER SIDE ACCESS AUTHORIZATION MODULE
  4. **
  5. **    Containts the code for keeping track on server hostnames,
  6. **    port numbers, scheme names, usernames, passwords
  7. **    (and servers' public keys).
  8. **
  9. ** IMPORTANT:
  10. **    Routines in this module use dynamic allocation, but free
  11. **    automatically all the memory reserved by them.
  12. **
  13. **    Therefore the caller never has to (and never should)
  14. **    free() any object returned by these functions.
  15. **
  16. **    Therefore also all the strings returned by this package
  17. **    are only valid until the next call to the same function
  18. **    is made. This approach is selected, because of the nature
  19. **    of access authorization: no string returned by the package
  20. **    needs to be valid longer than until the next call.
  21. **
  22. **    This also makes it easy to plug the AA package in:
  23. **    you don't have to ponder whether to free() something
  24. **    here or is it done somewhere else (because it is always
  25. **    done somewhere else).
  26. **
  27. **    The strings that the package needs to store are copied
  28. **    so the original strings given as parameters to AA
  29. **    functions may be freed or modified with no side effects.
  30. **
  31. **    The AA package does not free() anything else than what
  32. **    it has itself allocated.
  33. **
  34. ** AUTHORS:
  35. **    AL    Ari Luotonen    luotonen@dxcern.cern.ch
  36. **
  37. ** HISTORY:
  38. **
  39. **
  40. ** BUGS:
  41. **
  42. **
  43. */
  44.  
  45. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  46. /* All Rights Reserved */
  47.  
  48. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  49. /* All Rights Reserved */
  50.  
  51. /* This header file contains common preprocessor symbol   */
  52. /* definitions that were previously duplicated throughout */
  53. /* the header files. Those definitions were moved here    */
  54. /* and replaced with a #include of this header file.      */
  55. /* This was done to purify the header files for GST       */
  56. /* processing.                                            */
  57.  
  58. typedef unsigned int size_t;
  59. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  60. /* All Rights Reserved */
  61.  
  62. /* This header file contains common preprocessor symbol   */
  63. /* definitions that were previously duplicated throughout */
  64. /* the header files. Those definitions were moved here    */
  65. /* and replaced with a #include of this header file.      */
  66. /* This was done to purify the header files for GST       */
  67. /* processing.                                            */
  68.  
  69. /***
  70. *
  71. *     ANSI copying functions
  72. *
  73. ***/
  74.  
  75. extern void *memcpy(void *, const void *, size_t);
  76. extern void *memmove(void *, const void *, size_t);
  77. extern char *strcpy(char *, const char *);
  78. extern char *strncpy(char *, const char *, size_t);
  79.  
  80.  
  81. /***
  82. *
  83. *     ANSI concatenation functions
  84. *
  85. ***/
  86.  
  87. extern char *strcat(char *, const char *);
  88. extern char *strncat(char *, const char *, size_t);
  89.  
  90.  
  91. /***
  92. *
  93. *     ANSI comparison functions
  94. *
  95. ***/
  96.  
  97. extern int memcmp(const void *, const void *, size_t);
  98. extern int strcmp(const char *, const char *);
  99. extern int strcoll(const char *, const char *);
  100. extern int strncmp(const char *, const char *, size_t);
  101. extern size_t strxfrm(char *, const char *, size_t);
  102.  
  103.  
  104. /***
  105. *
  106. *     ANSI search functions
  107. *
  108. ***/
  109.  
  110. extern void *memchr(const void *, int, size_t);
  111. extern char *strchr(const char *, int);
  112. extern size_t strcspn(const char *, const char *);
  113. extern char *strpbrk(const char *, const char *);
  114. extern char *strrchr(const char *, int);
  115. extern size_t strspn(const char *, const char *);
  116. extern char *strstr(const char *, const char *);
  117. extern char *strtok(char *, const char *);
  118.  
  119.  
  120. /***
  121. *
  122. *     ANSI miscellaneous functions
  123. *
  124. ***/
  125.  
  126. extern void *memset(void *, int, size_t);
  127. extern char *strerror(int);
  128. extern size_t strlen(const char *);
  129.  
  130. /***
  131. *
  132. *     SAS string and memory functions.
  133. *
  134. ***/
  135.  
  136. extern int stcarg(const char *, const char *);
  137. extern int stccpy(char *, const char *, int);
  138. extern int stcgfe(char *, const char *);
  139. extern int stcgfn(char *, const char *);
  140. extern int stcis(const char *, const char *);
  141. extern int stcisn(const char *, const char *);
  142. extern int __stcd_i(const char *, int *);
  143. extern int __stcd_l(const char *, long *);
  144. extern int stch_i(const char *, int *);
  145. extern int stch_l(const char *, long *);
  146. extern int stci_d(char *, int);
  147. extern int stci_h(char *, int);
  148. extern int stci_o(char *, int);
  149. extern int stcl_d(char *, long);
  150. extern int __stcl_h(char *, long);
  151. extern int __stcl_o(char *, long);
  152. extern int stco_i(const char *, int *);
  153. extern int stco_l(const char *, long *);
  154. extern int stcpm(const char *, const char *, char **);
  155. extern int stcpma(const char *, const char *);
  156. extern int stcsma(const char *, const char *);
  157. extern int astcsma(const char *, const char *);
  158. extern int stcu_d(char *, unsigned);
  159. extern int __stcul_d(char *, unsigned long);
  160.  
  161. extern char *stpblk(const char *);
  162. extern char *stpbrk(const char *, const char *);
  163. extern char *stpchr(const char *, int);
  164. extern char *stpcpy(char *, const char *);
  165. extern char *__stpcpy(char *, const char *);
  166. extern char *stpdate(char *, int, const char *);
  167. extern char *stpsym(const char *, char *, int);
  168. extern char *stptime(char *, int, const char *);
  169. extern char *stptok(const char *, char *, int, const char *);
  170.  
  171. extern int strbpl(char **, int, const char *);
  172. extern int stricmp(const char *, const char *);
  173. extern char *strdup(const char *);
  174. extern void strins(char *, const char *);
  175. extern int strmid(const char *, char *, int, int);
  176. extern char *__strlwr(char *);
  177. extern void strmfe(char *, const char *, const char *);
  178. extern void strmfn(char *, const char *, const char *, const char *, 
  179.                    const char *);
  180. extern void strmfp(char *, const char *, const char *);
  181. extern int strnicmp(const char *, const char *, size_t);
  182. extern char *strnset(char *, int, int);
  183.  
  184. extern char *stpchrn(const char *, int);
  185. extern char *strrev(char *);
  186. extern char *strset(char *, int);
  187. extern void strsfn(const char *, char *, char *, char *, char *);
  188. extern char *__strupr(char *);
  189. extern int stspfp(char *, int *);
  190. extern void strsrt(char *[], int);
  191.  
  192. extern int stcgfp(char *, const char *);
  193.  
  194. extern void *memccpy(void *, const void *, int, unsigned);
  195. extern void movmem(const void *, void *, unsigned);
  196. extern void repmem(void *, const void *, size_t, size_t);
  197. extern void setmem(void *, unsigned, int);
  198. extern void __swmem(void *, void *, unsigned);
  199. /* for BSD compatibility */
  200. /**
  201. *
  202. * Builtin function definitions
  203. *
  204. **/
  205.  
  206. extern size_t  __builtin_strlen(const char *);
  207. extern int     __builtin_strcmp(const char *, const char *);
  208. extern char   *__builtin_strcpy(char *, const char *);
  209.  
  210. extern void   *__builtin_memset(void *, int, size_t);
  211. extern int     __builtin_memcmp(const void *, const void *, size_t);
  212. extern void   *__builtin_memcpy(void *, const void *, size_t);
  213.  
  214. extern int __builtin_max(int, int);
  215. extern int __builtin_min(int, int);
  216. extern int __builtin_abs(int);
  217.  
  218. /*                                                    Utitlity macros for the W3 code library
  219.                                   MACROS FOR GENERAL USE
  220.                                              
  221.    Generates: HTUtils.h
  222.    
  223.    See also: the system dependent file "tcp.h"
  224.    
  225.  */
  226.  
  227. /*
  228. **    $VER: types.h 40.1 (10.8.93)
  229. **    Includes Release 40.13
  230. **
  231. **    Data typing.  Must be included before any other Amiga include.
  232. **
  233. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  234. **        All Rights Reserved
  235. */
  236.  
  237.  
  238.   /*  WARNING: APTR was redefined for the V36 Includes!  APTR is a   */
  239.  /*  32-Bit Absolute Memory Pointer.  C pointer math will not        */
  240. /*  operate on APTR --    use "ULONG *" instead.               */
  241. typedef void           *APTR;        /* 32-bit untyped pointer */
  242. typedef long        LONG;        /* signed 32-bit quantity */
  243. typedef unsigned long    ULONG;        /* unsigned 32-bit quantity */
  244. typedef unsigned long    LONGBITS;   /* 32 bits manipulated individually */
  245. typedef short        WORD;        /* signed 16-bit quantity */
  246. typedef unsigned short    UWORD;        /* unsigned 16-bit quantity */
  247. typedef unsigned short    WORDBITS;   /* 16 bits manipulated individually */
  248. typedef signed char    BYTE;        /* signed 8-bit quantity */
  249. typedef unsigned char    UBYTE;        /* unsigned 8-bit quantity */
  250. typedef unsigned char    BYTEBITS;   /* 8 bits manipulated individually */
  251. typedef unsigned short    RPTR;        /* signed relative pointer */
  252.  
  253. typedef unsigned char  *STRPTR;     /* string pointer (NULL terminated) */
  254. /* For compatibility only: (don't use in new code) */
  255. typedef short        SHORT;        /* signed 16-bit quantity (use WORD) */
  256. typedef unsigned short    USHORT;     /* unsigned 16-bit quantity (use UWORD) */
  257. typedef short        COUNT;
  258. typedef unsigned short    UCOUNT;
  259. typedef ULONG        CPTR;
  260.  
  261.  
  262. /* Types with specific semantics */
  263. typedef float        FLOAT;
  264. typedef double        DOUBLE;
  265. typedef short        BOOL;
  266. typedef unsigned char    TEXT;
  267.  
  268. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  269. /* All Rights Reserved */
  270.  
  271. /* This header file contains common preprocessor symbol   */
  272. /* definitions that were previously duplicated throughout */
  273. /* the header files. Those definitions were moved here    */
  274. /* and replaced with a #include of this header file.      */
  275. /* This was done to purify the header files for GST       */
  276. /* processing.                                            */
  277.  
  278.  /* #define LIBRARY_VERSION is now obsolete.  Please use LIBRARY_MINIMUM */
  279. /* or code the specific minimum library version you require.        */
  280.   typedef BOOL BOOLEAN;
  281. /*
  282.  
  283. Debug message control.
  284.  
  285.  */
  286. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  287. /* All Rights Reserved */
  288.  
  289.  
  290. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  291. /* All Rights Reserved */
  292.  
  293. /* This header file contains common preprocessor symbol   */
  294. /* definitions that were previously duplicated throughout */
  295. /* the header files. Those definitions were moved here    */
  296. /* and replaced with a #include of this header file.      */
  297. /* This was done to purify the header files for GST       */
  298. /* processing.                                            */
  299.  
  300. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  301. /* All Rights Reserved */
  302.  
  303. /* This header file contains common preprocessor symbol   */
  304. /* definitions that were previously duplicated throughout */
  305. /* the header files. Those definitions were moved here    */
  306. /* and replaced with a #include of this header file.      */
  307. /* This was done to purify the header files for GST       */
  308. /* processing.                                            */
  309.  
  310. typedef char *va_list;
  311. typedef unsigned long fpos_t;
  312.  
  313. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  314. /* All Rights Reserved */
  315.  
  316. /* This header file contains common preprocessor symbol   */
  317. /* definitions that were previously duplicated throughout */
  318. /* the header files. Those definitions were moved here    */
  319. /* and replaced with a #include of this header file.      */
  320. /* This was done to purify the header files for GST       */
  321. /* processing.                                            */
  322.  
  323. /**
  324. *
  325. * Definitions associated with __iobuf._flag
  326. *
  327. **/
  328.  
  329. struct __iobuf {
  330.     struct __iobuf *_next;
  331.     unsigned char *_ptr;    /* current buffer pointer */
  332.     int _rcnt;                /* current byte count for reading */
  333.     int _wcnt;                /* current byte count for writing */
  334.     unsigned char *_base;    /* base address of I/O buffer */
  335.     int _size;            /* size of buffer */
  336.     int _flag;                /* control flags */
  337.     int _file;                /* file descriptor */
  338.     unsigned char _cbuff;    /* single char buffer */
  339. };
  340.  
  341. typedef struct __iobuf FILE;
  342.  
  343. extern struct __iobuf __iob[];
  344.  
  345. /***
  346. *
  347. *     Prototypes for ANSI standard functions.
  348. *
  349. ***/
  350.  
  351.  
  352. extern int remove(const char *);
  353. extern int rename(const char *, const char *);
  354. extern FILE *tmpfile(void);
  355. extern char *tmpnam(char *s);
  356.  
  357. extern int fclose(FILE *);
  358. extern int fflush(FILE *);
  359. extern FILE *fopen(const char *, const char *);
  360. extern FILE *freopen(const char *, const char *, FILE *);
  361. extern void setbuf(FILE *, char *);
  362. extern int setvbuf(FILE *, char *, int, size_t);
  363.  
  364. extern int fprintf(FILE *, const char *, ...);
  365. extern int fscanf(FILE *, const char *, ...);
  366. extern int printf(const char *, ...);
  367. extern int __builtin_printf(const char *, ...);
  368. extern int scanf(const char *, ...);
  369. extern int sprintf(char *, const char *, ...);
  370. extern int sscanf(const char *, const char *, ...);
  371. extern int vfprintf(FILE *, const char *, va_list);
  372. extern int vprintf(const char *, va_list);
  373. extern int vsprintf(char *, const char *, va_list);
  374.  
  375. extern int fgetc(FILE *);
  376. extern char *fgets(char *, int, FILE *);
  377. extern int fputc(int, FILE *);
  378. extern int fputs(const char *, FILE *);
  379. extern int getc(FILE *);
  380. extern int getchar(void);
  381. extern char *gets(char *);
  382. extern int putc(int, FILE *);
  383.  
  384. extern int putchar(int);
  385. extern int puts(const char *);
  386. extern int ungetc(int, FILE *);
  387.  
  388. extern size_t fread(void *, size_t, size_t, FILE *);
  389. extern size_t fwrite(const void *, size_t, size_t, FILE *);
  390. extern int fgetpos(FILE *, fpos_t *);
  391. extern int fseek(FILE *, long int, int);
  392. extern int fsetpos(FILE *, const fpos_t *);
  393. extern long int ftell(FILE *);
  394. extern void rewind(FILE *);
  395. extern void clearerr(FILE *);
  396. extern int feof(FILE *);
  397. extern int ferror(FILE *);
  398. extern void perror(const char *);
  399.  
  400. /* defines for mode of access() */
  401. /***
  402. *
  403. *     Prototypes for Non-ANSI functions.
  404. *
  405. ***/
  406.  
  407. extern int __io2errno(int);
  408. extern int fcloseall(void);
  409. extern FILE *fdopen(int, const char *);
  410. extern int fhopen(long, int);
  411. extern int fgetchar(void);
  412. extern int fileno(FILE *);
  413. extern int flushall(void);
  414. extern void fmode(FILE *, int);
  415. extern int _writes(const char *, ...);
  416. extern int _tinyprintf(char *, ...);
  417. extern int fputchar(int);
  418. extern void setnbf(FILE *);
  419. extern int __fillbuff(FILE *);
  420. extern int __flushbuff(int, FILE *);
  421. extern int __access(const char *, int);
  422. extern int access(const char *, int);
  423. extern int chdir(const char *);
  424. extern int chmod(const char *, int);
  425. extern char *getcwd(char *, int);
  426. extern int unlink(const char *);
  427. extern int poserr(const char *);
  428.  
  429. /***
  430. *
  431. *     The following routines allow for raw console I/O.
  432. *
  433. ***/
  434.  
  435. int rawcon(int);
  436. int getch(void);
  437.  
  438. extern unsigned long __fmask;
  439. extern int __fmode;
  440.  
  441.         extern int WWW_TraceFlag;
  442. /*
  443.  
  444. Standard C library for malloc() etc
  445.  
  446.  */
  447. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  448. /* All Rights Reserved */
  449.  
  450.  
  451. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  452. /* All Rights Reserved */
  453.  
  454. /* This header file contains common preprocessor symbol   */
  455. /* definitions that were previously duplicated throughout */
  456. /* the header files. Those definitions were moved here    */
  457. /* and replaced with a #include of this header file.      */
  458. /* This was done to purify the header files for GST       */
  459. /* processing.                                            */
  460.  
  461. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  462. /* All Rights Reserved */
  463.  
  464. /* This header file contains common preprocessor symbol   */
  465. /* definitions that were previously duplicated throughout */
  466. /* the header files. Those definitions were moved here    */
  467. /* and replaced with a #include of this header file.      */
  468. /* This was done to purify the header files for GST       */
  469. /* processing.                                            */
  470.  
  471. typedef char wchar_t;
  472. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  473. /* All Rights Reserved */
  474.  
  475. /* This header file contains common preprocessor symbol   */
  476. /* definitions that were previously duplicated throughout */
  477. /* the header files. Those definitions were moved here    */
  478. /* and replaced with a #include of this header file.      */
  479. /* This was done to purify the header files for GST       */
  480. /* processing.                                            */
  481.  
  482. typedef struct {
  483.             int quot;
  484.             int rem;
  485.         } div_t;
  486.  
  487. typedef struct {
  488.             long int quot;
  489.             long int rem;
  490.         } ldiv_t;
  491.  
  492. extern char __mb_cur_max;
  493.  
  494. extern double atof(const char *);
  495. extern int atoi(const char *);
  496. extern long int atol(const char *);
  497.  
  498. extern double strtod(const char *, char **);
  499. extern long int strtol(const char *, char **, int);
  500. extern unsigned long int strtoul(const char *, char **, int);
  501.  
  502.  
  503. extern int rand(void);
  504. extern void srand(unsigned int);
  505.  
  506.  
  507. /***
  508. *
  509. *     ANSI memory management functions
  510. *
  511. ***/
  512.  
  513. extern void *calloc(size_t, size_t);
  514. extern void free(void *);
  515. extern void *malloc(size_t);
  516. extern void *realloc(void *, size_t);
  517.  
  518. extern void *halloc(unsigned long);              /*  Extension  */
  519. extern void *__halloc(unsigned long);            /*  Extension  */
  520. /***
  521. *
  522. *     ANSI environment functions
  523. *
  524. ***/
  525.  
  526. extern void abort(void);
  527. extern int atexit(void (*)(void));
  528. extern void exit(int);
  529. extern char *__getenv(const char *);
  530. extern char *getenv(const char *);
  531. extern int system(const char *);
  532.  
  533.  
  534. /***
  535. *
  536. *     ANSI searching and sorting functions
  537. *
  538. ***/
  539.  
  540. extern void *bsearch(const void *, const void *, size_t, size_t,
  541.                      int (*)(const void *, const void *));
  542. extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
  543.  
  544.  
  545. /***
  546. *
  547. *     ANSI integer arithmetic functions
  548. *
  549. ***/
  550. extern int abs(int);
  551. extern div_t div(int, int);
  552. extern long int labs(long int);
  553. extern ldiv_t ldiv(long int, long int);
  554.  
  555.  
  556. /***
  557. *
  558. *     ANSI multibyte character functions
  559. *
  560. ***/
  561.  
  562. extern int mblen(const char *, size_t);
  563. extern int mbtowc(wchar_t *, const char *, size_t);
  564. extern int wctomb(char *, wchar_t);
  565. extern size_t mbstowcs(wchar_t *, const char *, size_t);
  566. extern size_t wcstombs(char *, const wchar_t *, size_t);
  567.  
  568.  
  569. /***
  570. *
  571. *     SAS Level 2 memory allocation functions
  572. *
  573. ***/
  574.  
  575. extern void *getmem(unsigned int);
  576. extern void *getml(long);
  577. extern void rlsmem(void *, unsigned int);
  578. extern void rlsml(void *, long);
  579. extern int bldmem(int);
  580. extern long sizmem(void);
  581. extern long chkml(void);
  582. extern void rstmem(void);
  583.  
  584.  
  585. /***
  586. *
  587. *     SAS Level 1 memory allocation functions
  588. *
  589. ***/
  590.  
  591. extern void *sbrk(unsigned int);
  592. extern void *lsbrk(long);
  593. extern int rbrk(void);
  594. extern void __stdargs _MemCleanup(void);
  595.  
  596. extern unsigned long _MemType;
  597. extern void *_MemHeap;
  598. extern unsigned long _MSTEP;
  599.  
  600.  
  601. /**
  602. *
  603. * SAS Sort functions
  604. *
  605. */
  606.  
  607. extern void dqsort(double *, size_t);
  608. extern void fqsort(float *, size_t);
  609. extern void lqsort(long *, size_t);
  610. extern void sqsort(short *, size_t);
  611. extern void tqsort(char **, size_t);
  612.  
  613.  
  614. /***
  615. *
  616. *     SAS startup, exit and environment functions.
  617. *
  618. ***/
  619.  
  620. extern void __exit(int);
  621. extern void __stdargs __main(char *);
  622. extern void __stdargs __tinymain(char *);
  623. extern void __stdargs _XCEXIT(long);
  624. extern char *argopt(int, char**, char *, int *, char *);
  625. extern int iabs(int);
  626. extern int onexit(void (*)(void));
  627. extern int putenv(const char *);
  628.  
  629. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  630. /* All Rights Reserved */
  631.  
  632. /* This header file contains common preprocessor symbol   */
  633. /* definitions that were previously duplicated throughout */
  634. /* the header files. Those definitions were moved here    */
  635. /* and replaced with a #include of this header file.      */
  636. /* This was done to purify the header files for GST       */
  637. /* processing.                                            */
  638.  
  639. #pragma msg 148 ignore push   /* Ignore message if tag is undefined*/
  640. extern struct WBStartup *_WBenchMsg;  /* WorkBench startup, if the */
  641. #pragma msg 148 pop                   /* WorkBench.   Same as argv.*/
  642. /* The following two externs give you the information in the   */
  643. /* WBStartup structure parsed out to look like an (argc, argv) */
  644. /* pair.  Don't define them in your code;  just include this   */
  645. /* file and use them.  If the program was not run from         */
  646. /* WorkBench, _WBArgc will be zero.                            */
  647.  
  648. extern int _WBArgc;    /* Count of the number of WorkBench arguments */
  649. extern char **_WBArgv; /* The actual arguments                       */
  650.  
  651. /*
  652.  
  653. Macros for declarations
  654.  
  655.  */
  656. /*
  657.  
  658. Booleans
  659.  
  660.  */
  661. /* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
  662. /* #define GOOD(status) ((status)38;1)   VMS style status: test bit 0         */
  663. /* #define BAD(status)  (!GOOD(status))  Bit 0 set if OK, otherwise clear   */
  664.  
  665. /*      Inline Function WHITE: Is character c white space? */
  666. /*      For speed, include all control characters */
  667.  
  668. /*
  669.  
  670. Sucess (>=0) and failure (<0) codes
  671.  
  672.  */
  673.  
  674. /*                                                                 String handling for libwww
  675.                                          STRINGS
  676.                                              
  677.    Case-independent string comparison and allocations with copies etc
  678.    
  679.  */
  680. /*                                                    Utitlity macros for the W3 code library
  681.                                   MACROS FOR GENERAL USE
  682.                                              
  683.    Generates: HTUtils.h
  684.    
  685.    See also: the system dependent file "tcp.h"
  686.    
  687.  */
  688.  
  689. /*
  690.  
  691.    end of utilities  */
  692.  
  693.  
  694. extern int WWW_TraceFlag;       /* Global flag for all W3 trace */
  695.  
  696. extern  char * HTLibraryVersion;   /* String for help screen etc */
  697.  
  698. /*
  699.  
  700. Case-insensitive string comparison
  701.  
  702.    The usual routines (comp instead of cmp) had some problem.
  703.    
  704.  */
  705. extern int strcasecomp  ( char *a,  char *b);
  706. extern int strncasecomp ( char *a,  char *b, int n);
  707.  
  708. /*
  709.  
  710. Malloced string manipulation
  711.  
  712.  */
  713. extern char * HTSACopy (char **dest,  char *src);
  714. extern char * HTSACat  (char **dest,  char *src);
  715.  
  716. /*
  717.  
  718. Next word or quoted string
  719.  
  720.  */
  721. extern char * HTNextField (char** pstr);
  722.  
  723.  
  724. /*
  725.  
  726.    end
  727.    
  728.     */
  729.  
  730.  
  731. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  732. /* All Rights Reserved */
  733.  
  734.  
  735. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  736. /* All Rights Reserved */
  737.  
  738. /* This header file contains common preprocessor symbol   */
  739. /* definitions that were previously duplicated throughout */
  740. /* the header files. Those definitions were moved here    */
  741. /* and replaced with a #include of this header file.      */
  742. /* This was done to purify the header files for GST       */
  743. /* processing.                                            */
  744.  
  745. /*
  746.  
  747. Out Of Memory checking for malloc() return:
  748.  
  749.  */
  750. /*
  751.  
  752. Upper- and Lowercase macros
  753.  
  754.    The problem here is that toupper(x) is not defined officially unless isupper(x) is.
  755.    These macros are CERTAINLY needed on #if defined(pyr) || define(mips) or BDSI
  756.    platforms. For safefy, we make them mandatory.
  757.    
  758.  */
  759. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  760. /* All Rights Reserved. */
  761.  
  762.  
  763. /**
  764. *
  765. * This header file defines various ASCII character manipulation macros,
  766. * as follows:
  767. *
  768. *       isalpha(c)    non-zero if c is alpha
  769. *       isupper(c)    non-zero if c is upper case
  770. *       islower(c)    non-zero if c is lower case
  771. *       isdigit(c)    non-zero if c is a digit (0 to 9)
  772. *       isxdigit(c)   non-zero if c is a hexadecimal digit (0 to 9, A to F,
  773. *                   a to f)
  774. *       isspace(c)    non-zero if c is white space
  775. *       ispunct(c)    non-zero if c is punctuation
  776. *       isalnum(c)    non-zero if c is alpha or digit
  777. *       isprint(c)    non-zero if c is printable (including blank)
  778. *       isgraph(c)    non-zero if c is graphic (excluding blank)
  779. *       iscntrl(c)    non-zero if c is control character
  780. *       isascii(c)    non-zero if c is ASCII
  781. *       iscsym(c)     non-zero if valid character for C symbols
  782. *       iscsymf(c)    non-zero if valid first character for C symbols
  783. *
  784. **/
  785.  
  786. extern int isalnum(int);
  787. extern int isalpha(int);
  788. extern int iscntrl(int);
  789. extern int isdigit(int);
  790. extern int isgraph(int);
  791. extern int islower(int);
  792. extern int isprint(int);
  793. extern int ispunct(int);
  794. extern int isspace(int);
  795. extern int isupper(int);
  796. extern int isxdigit(int);
  797.  
  798. extern int tolower(int);
  799. extern int toupper(int);
  800.  
  801. extern char __ctype[];   /* character type table */
  802.  
  803. /****
  804. *
  805. *   Extensions to the ANSI standard.
  806. *
  807. *
  808. ****/
  809.  
  810. extern int isascii(int);
  811. extern int iscsym(int);
  812. extern int iscsymf(int);
  813.  
  814. extern int toascii(int);
  815.  
  816.  
  817.   /* Pyramid and Mips can't uppercase non-alpha */
  818. /*
  819.  
  820.    end of utilities  */
  821.  
  822. /*                                                                 String handling for libwww
  823.                                          STRINGS
  824.                                              
  825.    Case-independent string comparison and allocations with copies etc
  826.    
  827.  */
  828. /*
  829.  
  830.    end
  831.    
  832.     */
  833.  
  834. /*                                                   HTParse:  URL parsing in the WWW Library
  835.                                          HTPARSE
  836.                                              
  837.    This module of the WWW library contains code to parse URLs and various related things.
  838.    Implemented by HTParse.c .
  839.    
  840.  */
  841. /*                                                    Utitlity macros for the W3 code library
  842.                                   MACROS FOR GENERAL USE
  843.                                              
  844.    Generates: HTUtils.h
  845.    
  846.    See also: the system dependent file "tcp.h"
  847.    
  848.  */
  849.  
  850. /*
  851.  
  852.    end of utilities  */
  853.  
  854.  
  855. /*
  856.  
  857.    The following are flag bits which may be ORed together to form a number to give the
  858.    'wanted' argument to HTParse.
  859.    
  860.  */
  861. /*
  862.  
  863. HTParse:  Parse a URL relative to another URL
  864.  
  865.    This returns those parts of a name which are given (and requested) substituting bits
  866.    from the related name where necessary.
  867.    
  868.   ON ENTRY
  869.   
  870.   aName                   A filename given
  871.                          
  872.   relatedName             A name relative to which aName is to be parsed
  873.                          
  874.   wanted                  A mask for the bits which are wanted.
  875.                          
  876.   ON EXIT,
  877.   
  878.   returns                 A pointer to a malloc'd string which MUST BE FREED
  879.                          
  880.  */
  881.  
  882. extern char * HTParse  (char * aName, char * relatedName, int wanted);
  883.  
  884.  
  885. /*
  886.  
  887. HTStrip: Strip white space off a string
  888.  
  889.   ON EXIT
  890.   
  891.    Return value points to first non-white character, or to 0 if none.
  892.    
  893.    All trailing white space is OVERWRITTEN with zero.
  894.    
  895.  */
  896. extern char * HTStrip(char * s);
  897. /*
  898.  
  899. HTSimplify: Simplify a UTL
  900.  
  901.    A URL is allowed to contain the seqeunce xxx/../ which may be replaced by "" , and the
  902.    seqeunce "/./" which may be replaced by "/". Simplification helps us recognize
  903.    duplicate filenames. It doesn't deal with soft links, though. The new (shorter)
  904.    filename overwrites the old.
  905.    
  906.  */
  907. /*
  908. **      Thus,   /etc/junk/../fred       becomes /etc/fred
  909. **              /etc/junk/./fred        becomes /etc/junk/fred
  910. */
  911. extern void HTSimplify(char * filename);
  912. /*
  913.  
  914. HTRelative:  Make Relative (Partial) URL
  915.  
  916.    This function creates and returns a string which gives an expression of one address as
  917.    related to another. Where there is no relation, an absolute address is retured.
  918.    
  919.   ON ENTRY,
  920.   
  921.    Both names must be absolute, fully qualified names of nodes (no anchor bits)
  922.    
  923.   ON EXIT,
  924.   
  925.    The return result points to a newly allocated name which, if parsed by HTParse relative
  926.    to relatedName, will yield aName. The caller is responsible for freeing the resulting
  927.    name later.
  928.    
  929.  */
  930. extern char * HTRelative(char * aName, char *relatedName);
  931. /*
  932.  
  933. HTEscape:  Encode unacceptable characters in string
  934.  
  935.    This funtion takes a string containing any sequence of ASCII characters, and returns a
  936.    malloced string containing the same infromation but with all "unacceptable" characters
  937.    represented in the form %xy where X and Y are two hex digits.
  938.    
  939.  */
  940. extern char * HTEscape (char * str);
  941.  
  942.  
  943. /*
  944.  
  945. HTUnEscape: Decode %xx escaped characters
  946.  
  947.    This function takes a pointer to a string in which character smay have been encoded in
  948.    %xy form, where xy is the acsii hex code for character 16x+y. The string is converted
  949.    in place, as it will never grow.
  950.    
  951.  */
  952. extern char * HTUnEscape ( char * str);
  953.  
  954.  
  955. /*
  956.  
  957.    end of HTParse
  958.    
  959.     */
  960.  
  961. /*  */
  962.  
  963. /*              List object
  964. **
  965. **      The list object is a generic container for storing collections
  966. **      of things in order.
  967. */
  968. /*                                                    Utitlity macros for the W3 code library
  969.                                   MACROS FOR GENERAL USE
  970.                                              
  971.    Generates: HTUtils.h
  972.    
  973.    See also: the system dependent file "tcp.h"
  974.    
  975.  */
  976.  
  977. /*
  978.  
  979.    end of utilities  */
  980.  
  981.  
  982. typedef struct _HTList HTList;
  983.  
  984. struct _HTList {
  985.   void * object;
  986.   HTList * next;
  987.   HTList * last;
  988. };
  989.  
  990. extern HTList * HTList_new (void);
  991. extern void     HTList_delete (HTList *me);
  992.  
  993. /*      Add object to START of list
  994. */
  995. extern void     HTList_addObject (HTList *me, void *newObject);
  996. extern void     HTList_addObjectAtEnd (HTList *me, void *newObject);
  997.  
  998.  
  999. extern BOOLEAN     HTList_removeObject (HTList *me, void *oldObject);
  1000. extern void *   HTList_removeLastObject (HTList *me);
  1001. extern void *   HTList_removeFirstObject (HTList *me);
  1002. extern int      HTList_count (HTList *me);
  1003. extern int      HTList_indexOf (HTList *me, void *object);
  1004. extern void *   HTList_objectAt (HTList *me, int position);
  1005.  
  1006. /* Fast macro to traverse the list. Call it first with copy of list header :
  1007.    it returns the first object and increments the passed list pointer.
  1008.    Call it with the same variable until it returns NULL. */
  1009. /*
  1010.  
  1011.     */
  1012.  
  1013. /*  */
  1014.  
  1015. /*      Displaying messages and getting input for WWW Library
  1016. **      =====================================================
  1017. **
  1018. **         May 92 Created By C.T. Barker
  1019. **         Feb 93 Portablized etc TBL
  1020. */
  1021.  
  1022. /*                                                    Utitlity macros for the W3 code library
  1023.                                   MACROS FOR GENERAL USE
  1024.                                              
  1025.    Generates: HTUtils.h
  1026.    
  1027.    See also: the system dependent file "tcp.h"
  1028.    
  1029.  */
  1030.  
  1031. /*
  1032.  
  1033.    end of utilities  */
  1034.  
  1035. /*          System dependencies in the W3 library
  1036.                    SYSTEM DEPENDENCIES
  1037.  
  1038.    System-system differences for TCP include files and macros. This
  1039.    file includes for each system the files necessary for network and
  1040.    file I/O.
  1041.  
  1042.   AUTHORS
  1043.  
  1044.   TBL             Tim Berners-Lee, W3 project, CERN, <timbl@info.cern.ch>
  1045.   EvA              Eelco van Asperen <evas@cs.few.eur.nl>
  1046.   MA              Marc Andreessen NCSA
  1047.   AT              Aleksandar Totic <atotic@ncsa.uiuc.edu>
  1048.   SCW              Susan C. Weber <sweber@kyle.eitech.com>
  1049.   MJW              Michael J Witbrock <witbrock@cmu.edu>
  1050.   MWM              Mike Meyer  <mwm@contessa.phone.net>
  1051.  
  1052.   HISTORY:
  1053.   22 Feb 91          Written (TBL) as part of the WWW library.
  1054.   16 Jan 92          PC code from EvA
  1055.   22 Apr 93          Merged diffs bits from xmosaic release
  1056.   29 Apr 93          Windows/NT code from SCW
  1057.  
  1058.   Much of the cross-system portability stuff has been intentionally
  1059.   REMOVED from this version of the library by Marc A in order to
  1060.   discourage attempts to make "easy" ports of Mosaic for X to non-Unix
  1061.   platforms.  The library needs to be rewritten from the ground up; in
  1062.   the meantime, Unix is *all* we support or intend to support with
  1063.   this set of source code.
  1064.  
  1065. */
  1066.  
  1067. /*
  1068.  
  1069. Default values
  1070.  
  1071.    These values may be reset and altered by system-specific sections
  1072.    later on.  there are also a bunch of defaults at the end .
  1073.  
  1074.  */
  1075. /* Default values of those: */
  1076. /* Unless stated otherwise, */
  1077. typedef struct sockaddr_in SockA;  /* See netinet/in.h */
  1078.  
  1079.  
  1080. /* Solaris. */
  1081. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  1082. /* All Rights Reserved */
  1083.  
  1084. /* Use builtin strdup when appropriate. */
  1085. /*
  1086.  
  1087. VAX/VMS
  1088.  
  1089.    Under VMS, there are many versions of TCP-IP. Define one if you do
  1090.    not use Digital's UCX product:
  1091.  
  1092.   UCX              DEC's "Ultrix connection" (default)
  1093.   WIN_TCP          From Wollongong, now GEC software.
  1094.   MULTINET          From SRI, now from TGV Inv.
  1095.   DECNET          Cern's TCP socket emulation over DECnet
  1096.  
  1097.    The last three do not interfere with the
  1098.    unix i/o library, and so they need special calls to read, write and
  1099.    close sockets. In these cases the socket number is a VMS channel
  1100.    number, so we make the @@@ HORRIBLE @@@ assumption that a channel
  1101.    number will be greater than 10 but a unix file descriptor less than
  1102.    10.    It works.
  1103.  
  1104.  */
  1105. /*
  1106.  
  1107. SCO ODT unix version
  1108.  
  1109.  */
  1110.  
  1111. /*
  1112.  
  1113. MIPS unix
  1114.  
  1115.  */
  1116. /* Mips hack (bsd4.3/sysV mixture...) */
  1117.  
  1118. /*
  1119.  
  1120. Regular BSD unix versions
  1121.  
  1122.    These are a default unix where not already defined specifically.
  1123.  
  1124.  */
  1125.      typedef int bool_t;
  1126.      typedef long dev_t;
  1127.      typedef int enum_t;        /* For device numbers */
  1128.      typedef unsigned long ino_t;    /* For file serial numbers */
  1129.      typedef unsigned short mode_t;    /* For file types and modes */
  1130.      typedef short nlink_t;        /* For link counts */
  1131.      typedef long off_t;        /* For file offsets and sizes */
  1132.      typedef long pid_t;        /* For process and session IDs */
  1133.      typedef long gid_t;        /* For group IDs */
  1134.      typedef long uid_t;        /* For user IDs */
  1135.      typedef long time_t;        /* For times in seconds */
  1136.       typedef int ssize_t;        /* Signed version of size_t */
  1137.      typedef unsigned short __site_t;    /* see stat.h */
  1138.      typedef unsigned short __cnode_t;    /* see stat.h */
  1139.    typedef long __daddr_t;        /* For disk block addresses */
  1140.    typedef char *__caddr_t;        /* For character addresses */
  1141.    typedef long __swblk_t;
  1142.  
  1143.      typedef __caddr_t        caddr_t;   /* also in ptrace.h */
  1144.    typedef unsigned char  ubit8;
  1145.    typedef unsigned short ubit16;
  1146.    typedef unsigned long  ubit32;
  1147.    typedef char       sbit8;
  1148.    typedef short      sbit16;
  1149.    typedef long       sbit32;
  1150.  
  1151.    typedef ubit8      u_char;
  1152.    typedef ubit16      u_short;
  1153.    typedef ubit32      u_long;
  1154.    typedef ubit32      u_int;
  1155.  
  1156.    typedef __swblk_t      swblk_t;
  1157.    typedef __daddr_t      daddr_t;
  1158.    typedef __site_t      site_t;
  1159.    typedef __cnode_t      cnode_t;
  1160.  
  1161.    typedef long       paddr_t;
  1162.    typedef short      cnt_t;
  1163.    typedef unsigned int   space_t;
  1164.    typedef unsigned int   prot_t;
  1165.    typedef unsigned long  cdno_t;
  1166.    typedef unsigned short use_t;
  1167.  
  1168.    typedef struct _physadr { int r[1]; } *physadr;
  1169.    typedef struct _quad { long val[2]; } quad;
  1170.  
  1171.    typedef char spu_t;
  1172.  
  1173. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  1174. /* All Rights Reserved */
  1175.  
  1176. /* This header file contains common preprocessor symbol   */
  1177. /* definitions that were previously duplicated throughout */
  1178. /* the header files. Those definitions were moved here    */
  1179. /* and replaced with a #include of this header file.      */
  1180. /* This was done to purify the header files for GST       */
  1181. /* processing.                                            */
  1182.  
  1183. /* Types, macros, etc. for select() */
  1184.  
  1185. /*
  1186.  * MAXFUPLIM is the absolute limit of open files per process.  No process,
  1187.  * even super-user processes may increase u.u_maxof beyond MAXFUPLIM.
  1188.  * MAXFUPLIM means maximum files upper limit.
  1189.  * Important Note:  This definition should actually go into h/param.h, but
  1190.  * since it is needed by the select() macros which follow, it had to go here.
  1191.  * I did not put it in both files since h/param.h includes this file and that
  1192.  * would be error prone anyway.
  1193.  */
  1194. /*
  1195.  * These macros are used for select().  select() uses bit masks of file
  1196.  * descriptors in longs.  These macros manipulate such bit fields (the
  1197.  * file sysrem macros uses chars).  FD_SETSIZE may be defined by the user,
  1198.  * but must be >= u.u_highestfd + 1.  Since we know the absolute limit on
  1199.  * number of per process open files is 2048, we need to define FD_SETSIZE
  1200.  * to be large enough to accomodate this many file descriptors.  Unless the
  1201.  * user has this many files opened, he should redefine FD_SETSIZE to a
  1202.  * smaller number.
  1203.  */
  1204.      typedef long fd_mask;
  1205.  
  1206.      typedef struct fd_set {
  1207.        fd_mask fds_bits[(((128)+(((sizeof(fd_mask) * 8))-1))/((sizeof(fd_mask) * 8)))];
  1208.      } fd_set;
  1209.  
  1210. /* #include <streams/streams.h>         not ultrix */
  1211. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  1212. /* All Rights Reserved */
  1213.  
  1214. /*
  1215.  * Amiga standard errno.h
  1216.  */
  1217. /* non-blocking and interrupt i/o */
  1218. /* ipc/network software */
  1219.  
  1220.     /* argument errors */
  1221.     /* operational errors */
  1222.     /* */
  1223. /* should be rearranged */
  1224. /* quotas & mush */
  1225. /* Network File System */
  1226. /* streams */
  1227. /* SystemV IPC */
  1228. /* SystemV Record Locking */
  1229. /* Non-standard UNIX, ie Amigados errors */
  1230. extern char *__sys_errlist[];
  1231. extern int __sys_nerr, errno;
  1232.  
  1233. /*
  1234. ** 4.x Unix time struct compatibility.
  1235. */
  1236.  
  1237. /*
  1238. **    $VER: timer.h 36.16 (25.1.91)
  1239. **    Includes Release 40.13
  1240. **
  1241. **    Timer device name and useful definitions.
  1242. **
  1243. **    (C) Copyright 1985-1993 Commodore-Amiga Inc.
  1244. **        All Rights Reserved
  1245. */
  1246.  
  1247. /*
  1248. **    $VER: io.h 39.0 (15.10.91)
  1249. **    Includes Release 40.13
  1250. **
  1251. **    Message structures used for device communication
  1252. **
  1253. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  1254. **        All Rights Reserved
  1255. */
  1256.  
  1257. /*
  1258. **    $VER: ports.h 39.0 (15.10.91)
  1259. **    Includes Release 40.13
  1260. **
  1261. **    Message ports and Messages.
  1262. **
  1263. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  1264. **        All Rights Reserved
  1265. */
  1266.  
  1267. /*
  1268. **    $VER: nodes.h 39.0 (15.10.91)
  1269. **    Includes Release 40.13
  1270. **
  1271. **    Nodes & Node type identifiers.
  1272. **
  1273. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  1274. **        All Rights Reserved
  1275. */
  1276.  
  1277. /*
  1278.  *  List Node Structure.  Each member in a list starts with a Node
  1279.  */
  1280.  
  1281. struct Node {
  1282.     struct  Node *ln_Succ;    /* Pointer to next (successor) */
  1283.     struct  Node *ln_Pred;    /* Pointer to previous (predecessor) */
  1284.     UBYTE   ln_Type;
  1285.     BYTE    ln_Pri;        /* Priority, for sorting */
  1286.     char    *ln_Name;        /* ID string, null terminated */
  1287. };    /* Note: word aligned */
  1288.  
  1289. /* minimal node -- no type checking possible */
  1290. struct MinNode {
  1291.     struct MinNode *mln_Succ;
  1292.     struct MinNode *mln_Pred;
  1293. };
  1294.  
  1295.  
  1296. /*
  1297. ** Note: Newly initialized IORequests, and software interrupt structures
  1298. ** used with Cause(), should have type NT_UNKNOWN.  The OS will assign a type
  1299. ** when they are first used.
  1300. */
  1301. /*----- Node Types for LN_TYPE -----*/
  1302. /*
  1303. **    $VER: lists.h 39.0 (15.10.91)
  1304. **    Includes Release 40.13
  1305. **
  1306. **    Definitions and macros for use with Exec lists
  1307. **
  1308. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  1309. **        All Rights Reserved
  1310. */
  1311.  
  1312. /*
  1313.  *  Full featured list header.
  1314.  */
  1315. struct List {
  1316.    struct  Node *lh_Head;
  1317.    struct  Node *lh_Tail;
  1318.    struct  Node *lh_TailPred;
  1319.    UBYTE   lh_Type;
  1320.    UBYTE   l_pad;
  1321. };    /* word aligned */
  1322.  
  1323. /*
  1324.  * Minimal List Header - no type checking
  1325.  */
  1326. struct MinList {
  1327.    struct  MinNode *mlh_Head;
  1328.    struct  MinNode *mlh_Tail;
  1329.    struct  MinNode *mlh_TailPred;
  1330. };    /* longword aligned */
  1331.  
  1332.  
  1333. /*
  1334.  *    Check for the presence of any nodes on the given list.    These
  1335.  *    macros are even safe to use on lists that are modified by other
  1336.  *    tasks.    However; if something is simultaneously changing the
  1337.  *    list, the result of the test is unpredictable.
  1338.  *
  1339.  *    Unless you first arbitrated for ownership of the list, you can't
  1340.  *    _depend_ on the contents of the list.  Nodes might have been added
  1341.  *    or removed during or after the macro executes.
  1342.  *
  1343.  *        if( IsListEmpty(list) )        printf("List is empty\n");
  1344.  */
  1345. /*
  1346. **    $VER: tasks.h 39.3 (18.9.92)
  1347. **    Includes Release 40.13
  1348. **
  1349. **    Task Control Block, Singals, and Task flags.
  1350. **
  1351. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  1352. **        All Rights Reserved
  1353. */
  1354.  
  1355. /* Please use Exec functions to modify task structure fields, where available.
  1356.  */
  1357. struct Task {
  1358.     struct  Node tc_Node;
  1359.     UBYTE   tc_Flags;
  1360.     UBYTE   tc_State;
  1361.     BYTE    tc_IDNestCnt;        /* intr disabled nesting*/
  1362.     BYTE    tc_TDNestCnt;        /* task disabled nesting*/
  1363.     ULONG   tc_SigAlloc;        /* sigs allocated */
  1364.     ULONG   tc_SigWait;        /* sigs we are waiting for */
  1365.     ULONG   tc_SigRecvd;        /* sigs we have received */
  1366.     ULONG   tc_SigExcept;        /* sigs we will take excepts for */
  1367.     UWORD   tc_TrapAlloc;        /* traps allocated */
  1368.     UWORD   tc_TrapAble;        /* traps enabled */
  1369.     APTR    tc_ExceptData;        /* points to except data */
  1370.     APTR    tc_ExceptCode;        /* points to except code */
  1371.     APTR    tc_TrapData;        /* points to trap data */
  1372.     APTR    tc_TrapCode;        /* points to trap code */
  1373.     APTR    tc_SPReg;            /* stack pointer        */
  1374.     APTR    tc_SPLower;        /* stack lower bound    */
  1375.     APTR    tc_SPUpper;        /* stack upper bound + 2*/
  1376.     void    (*tc_Switch)();        /* task losing CPU      */
  1377.     void    (*tc_Launch)();        /* task getting CPU  */
  1378.     struct  List tc_MemEntry;        /* Allocated memory. Freed by RemTask() */
  1379.     APTR    tc_UserData;        /* For use by the task; no restrictions! */
  1380. };
  1381.  
  1382. /*
  1383.  * Stack swap structure as passed to StackSwap()
  1384.  */
  1385. struct    StackSwapStruct {
  1386.     APTR    stk_Lower;    /* Lowest byte of stack */
  1387.     ULONG    stk_Upper;    /* Upper end of stack (size + Lowest) */
  1388.     APTR    stk_Pointer;    /* Stack pointer at switch point */
  1389. };
  1390.  
  1391. /*----- Flag Bits ------------------------------------------*/
  1392. /*----- Task States ----------------------------------------*/
  1393. /*----- Predefined Signals -------------------------------------*/
  1394. /****** MsgPort *****************************************************/
  1395.  
  1396. struct MsgPort {
  1397.     struct  Node mp_Node;
  1398.     UBYTE   mp_Flags;
  1399.     UBYTE   mp_SigBit;        /* signal bit number    */
  1400.     void   *mp_SigTask;        /* object to be signalled */
  1401.     struct  List mp_MsgList;    /* message linked list    */
  1402. };
  1403.  
  1404. /* mp_Flags: Port arrival actions (PutMsg) */
  1405. /****** Message *****************************************************/
  1406.  
  1407. struct Message {
  1408.     struct  Node mn_Node;
  1409.     struct  MsgPort *mn_ReplyPort;  /* message reply port */
  1410.     UWORD   mn_Length;            /* total message length, in bytes */
  1411.                     /* (include the size of the Message */
  1412.                     /* structure in the length) */
  1413. };
  1414.  
  1415. struct IORequest {
  1416.     struct  Message io_Message;
  1417.     struct  Device  *io_Device;     /* device node pointer  */
  1418.     struct  Unit    *io_Unit;        /* unit (driver private)*/
  1419.     UWORD   io_Command;        /* device command */
  1420.     UBYTE   io_Flags;
  1421.     BYTE    io_Error;            /* error or warning num */
  1422. };
  1423.  
  1424. struct IOStdReq {
  1425.     struct  Message io_Message;
  1426.     struct  Device  *io_Device;     /* device node pointer  */
  1427.     struct  Unit    *io_Unit;        /* unit (driver private)*/
  1428.     UWORD   io_Command;        /* device command */
  1429.     UBYTE   io_Flags;
  1430.     BYTE    io_Error;            /* error or warning num */
  1431.     ULONG   io_Actual;            /* actual number of bytes transferred */
  1432.     ULONG   io_Length;            /* requested number bytes transferred*/
  1433.     APTR    io_Data;            /* points to data area */
  1434.     ULONG   io_Offset;            /* offset for block structured devices */
  1435. };
  1436.  
  1437. /* library vector offsets for device reserved vectors */
  1438. /* io_Flags defined bits */
  1439. /* unit defintions */
  1440. struct timeval {
  1441.     ULONG tv_secs;
  1442.     ULONG tv_micro;
  1443. };
  1444.  
  1445. struct EClockVal {
  1446.     ULONG ev_hi;
  1447.     ULONG ev_lo;
  1448. };
  1449.  
  1450. struct timerequest {
  1451.     struct IORequest tr_node;
  1452.     struct timeval tr_time;
  1453. };
  1454.  
  1455. /* IO_COMMAND to use for adding a timer */
  1456. struct timezone {
  1457.     int tz_minuteswest;
  1458.     int tz_dsttime;
  1459. };
  1460.  
  1461. struct itimerval {
  1462.     struct timeval    it_value, it_interval;
  1463. };
  1464.  
  1465. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  1466. /* All Rights Reserved */
  1467.  
  1468. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  1469. /* All Rights Reserved */
  1470.  
  1471. /* This header file contains common preprocessor symbol   */
  1472. /* definitions that were previously duplicated throughout */
  1473. /* the header files. Those definitions were moved here    */
  1474. /* and replaced with a #include of this header file.      */
  1475. /* This was done to purify the header files for GST       */
  1476. /* processing.                                            */
  1477.  
  1478. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  1479. /* All Rights Reserved */
  1480.  
  1481. /* This header file contains common preprocessor symbol   */
  1482. /* definitions that were previously duplicated throughout */
  1483. /* the header files. Those definitions were moved here    */
  1484. /* and replaced with a #include of this header file.      */
  1485. /* This was done to purify the header files for GST       */
  1486. /* processing.                                            */
  1487.  
  1488. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  1489. /* All Rights Reserved */
  1490.  
  1491. /* This header file contains common preprocessor symbol   */
  1492. /* definitions that were previously duplicated throughout */
  1493. /* the header files. Those definitions were moved here    */
  1494. /* and replaced with a #include of this header file.      */
  1495. /* This was done to purify the header files for GST       */
  1496. /* processing.                                            */
  1497.  
  1498. typedef unsigned long clock_t;
  1499.  
  1500. /**
  1501. *
  1502. * This structure contains the unpacked time as returned by "gmtime".
  1503. *
  1504. */
  1505.  
  1506. struct tm {
  1507.     int tm_sec;      /* seconds after the minute */
  1508.     int tm_min;          /* minutes after the hour */
  1509.     int tm_hour;         /* hours since midnight */
  1510.     int tm_mday;         /* day of the month */
  1511.     int tm_mon;          /* months since January */
  1512.     int tm_year;         /* years since 1900 */
  1513.     int tm_wday;         /* days since Sunday */
  1514.     int tm_yday;         /* days since January 1 */
  1515.     int tm_isdst;        /* Daylight Savings Time flag */
  1516. };
  1517.  
  1518.  
  1519. /***
  1520. *
  1521. *     ANSI time functions.
  1522. *
  1523. ***/
  1524.  
  1525. extern clock_t clock(void);
  1526. extern double difftime(time_t, time_t);
  1527. extern time_t mktime(struct tm *);
  1528. extern time_t time(time_t *);
  1529.  
  1530. extern char *asctime(const struct tm *);
  1531. extern char *ctime(const time_t *);
  1532. extern struct tm *gmtime(const time_t *);
  1533. extern struct tm *localtime(const time_t *);
  1534. extern size_t strftime(char *, size_t, const char *, const struct tm *);
  1535.  
  1536.  
  1537. /***
  1538. *
  1539. *     SAS time functions
  1540. *
  1541. ***/
  1542.  
  1543. void getclk(unsigned char *);
  1544. int  chgclk(const unsigned char *);
  1545.  
  1546. void utunpk(long, char *);
  1547. long utpack(const char *);
  1548. int timer(unsigned int *);
  1549. int datecmp(const struct DateStamp *, const struct DateStamp *);
  1550.  
  1551. time_t __datecvt(const struct DateStamp *);
  1552. struct DateStamp *__timecvt(time_t);
  1553.  
  1554. /* for UNIX compatibility */
  1555. extern void      __tzset(void);
  1556. /***
  1557. *     SAS external variables
  1558. ***/
  1559.  
  1560. extern int  __daylight;
  1561. extern long __timezone;
  1562. extern char *__tzname[2];
  1563. extern char __tzstn[4];
  1564. extern char __tzdtn[4];
  1565. extern char *_TZ;
  1566.  
  1567.  
  1568. /*
  1569. ** stat structure used by fstat() and stat()
  1570. ** will not be compatible with your compiler's stat() and fstat()
  1571. */
  1572. struct stat
  1573. {
  1574.     dev_t    st_dev;
  1575.     ino_t    st_ino;
  1576.     mode_t    st_mode;
  1577.     nlink_t st_nlink;
  1578.     unsigned short st_reserved1; /* old st_uid, replaced spare positions */
  1579.     unsigned short st_reserved2; /* old st_gid, replaced spare positions */
  1580.     dev_t    st_rdev;
  1581.     off_t    st_size;
  1582.     time_t    st_atime;
  1583.     int    st_spare1;
  1584.     time_t    st_mtime;
  1585.     int    st_spare2;
  1586.     time_t    st_ctime;
  1587.     int    st_spare3;
  1588.     long    st_blksize;
  1589.     long    st_blocks;
  1590.     unsigned int    st_pad:30;
  1591.     unsigned int    st_acl:1;   /* set if there are optional ACL entries */
  1592.     unsigned int    st_remote:1;    /* Set if file is remote */
  1593.     dev_t    st_netdev;    /* ID of device containing */
  1594.                 /* network special file */
  1595.     ino_t    st_netino;    /* Inode number of network special file */
  1596.     __cnode_t    st_cnode;
  1597.     __cnode_t    st_rcnode;
  1598.     /* The site where the network device lives            */
  1599.     __site_t    st_netsite;
  1600.     short    st_fstype;
  1601.     /* Real device number of device containing the inode for this file*/
  1602.     dev_t    st_realdev;
  1603.     /* Steal three spare for the device site number           */
  1604.     unsigned short    st_basemode;
  1605.     unsigned short    st_spareshort;
  1606.     uid_t    st_uid;
  1607.     gid_t    st_gid;
  1608.     long    st_spare4[3];
  1609. };
  1610.  
  1611. /* st_mode will have bits set as follows */
  1612. /* the least significant 9 bits will be the unix
  1613. ** rwxrwxrwx bits (octal 777).
  1614. */
  1615.  
  1616. /*
  1617. ** Some signal definitions.  These are meant to build on the ones defined
  1618. ** in the SAS/C headers.  Will probably need to be changed for other
  1619. ** compilers.
  1620. */
  1621.  
  1622. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  1623. /* All Rights Reserved */
  1624.  
  1625.  
  1626. /**
  1627. *
  1628. * This header file contains definitions needed by the signal function.
  1629. *
  1630. **/
  1631.  
  1632. /**
  1633. *
  1634. * NSIG supposedly defines the number of signals recognized.  However,
  1635. * since not all signals are actually implemented under AmigaDOS, it actually
  1636. * is the highest legal signal number plus one.
  1637. *
  1638. */
  1639.  
  1640. /**
  1641. *
  1642. * The following symbols are the defined signals.
  1643. *
  1644. */
  1645.  
  1646. /***
  1647. *
  1648. * The following symbols are the special forms for the function pointer
  1649. * argument.  They specify certain standard actions that can be performed
  1650. * when the signal occurs.
  1651. *
  1652. ***/
  1653.  
  1654. /***
  1655. *
  1656. * Function declarations
  1657. *
  1658. ***/
  1659.  
  1660. extern void (*signal(int,void (*)(int)))(int);
  1661. extern int raise(int);
  1662.  
  1663. extern void (*__sigfunc[9])(int);
  1664.  
  1665. typedef int sig_atomic_t;
  1666.  
  1667. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  1668. /* All Rights Reserved */
  1669.  
  1670.  
  1671. /***
  1672. *
  1673. * The following symbols are used for the "open" and "creat" functions.
  1674. * They are generally UNIX-compatible, except for O_APPEND under MSDOS,
  1675. * which has been moved in order to accomodate the file sharing flags
  1676. * defined in MSDOS Version 3.
  1677. *
  1678. * Also, O_TEMP and O_RAW are SAS extensions.
  1679. *
  1680. ***/
  1681.  
  1682. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  1683. /* All Rights Reserved */
  1684.  
  1685. /* This header file contains common preprocessor symbol   */
  1686. /* definitions that were previously duplicated throughout */
  1687. /* the header files. Those definitions were moved here    */
  1688. /* and replaced with a #include of this header file.      */
  1689. /* This was done to purify the header files for GST       */
  1690. /* processing.                                            */
  1691.  
  1692. /***
  1693. *
  1694. * The following symbols are used for the "fcntl" function.
  1695. *
  1696. ***/
  1697.  
  1698. /***
  1699. *
  1700. * External definitions
  1701. *
  1702. ***/
  1703.  
  1704. extern int  __creat  (const char *, int);
  1705. extern long __lseek  (int, long, int);
  1706.  
  1707. extern int  __open   (const char *, int, ...);
  1708. extern int  __read   (int, void *, unsigned int);
  1709. extern int  __write  (int, const void *, unsigned int);
  1710. extern int  __close  (int);
  1711. extern int  open   (const char *, int, ...);
  1712. extern int  creat  (const char *, int);
  1713. extern int  read   (int, void *, unsigned int);
  1714. extern int  write  (int, const void *, unsigned int);
  1715. extern long lseek  (int, long, int);
  1716. extern long tell   (int);
  1717. extern int  close  (int);
  1718. extern int  unlink (const char *);
  1719. extern int  iomode (int, int);
  1720. extern int  isatty (int);
  1721.  
  1722. /* Copyright (c) 1993 SAS Institute, Inc., Cary, NC USA */
  1723. /* All Rights Reserved */
  1724.  
  1725. /* This header file contains common preprocessor symbol   */
  1726. /* definitions that were previously duplicated throughout */
  1727. /* the header files. Those definitions were moved here    */
  1728. /* and replaced with a #include of this header file.      */
  1729. /* This was done to purify the header files for GST       */
  1730. /* processing.                                            */
  1731.  
  1732. /* Copyright (c) 1992-1993 SAS Institute, Inc., Cary, NC USA */
  1733. /* All Rights Reserved */
  1734.  
  1735.  
  1736. /**
  1737. *
  1738. * The following symbols are specified in the ANSI C standard as limit
  1739. * values for various non-float characteristics.
  1740. *
  1741. **/
  1742.  
  1743. /*            Directory reading stuff - BSD or SYS V
  1744. */
  1745. /* This stuff comes BEFORE the defaults below */
  1746.  
  1747. /*
  1748. ** inet ioctl() operations.  Here rather than in more sensible places
  1749. ** mostly for Unix compatibility.
  1750. */
  1751. /*
  1752. ** ttychars.h - emulate Berkeley ttychars structs.  Mostly psyched out
  1753. **        from telnet/sys_bsd.c
  1754. */
  1755.  
  1756. struct ltchars {
  1757.     char    t_flushc;
  1758.     char    t_dsuspc;
  1759.     char    t_suspc;
  1760.     char    t_brkc;
  1761.     char    t_intrc;
  1762.     char    t_quitc;
  1763. };
  1764.  
  1765. /*  Comment out to prevent confusion for Manx 5.0
  1766.     Does anyone use this?
  1767.  
  1768. struct tchars {
  1769.     char    t_flushc;
  1770.     char    t_dsuspc;
  1771.     char    t_suspc;
  1772.     char    t_brkc;
  1773.     char    t_intrc;
  1774.     char    t_quitc;
  1775.     char    t_startc;
  1776.     char    t_stopc;
  1777.     char    t_syspc;
  1778.     char    t_eofc;
  1779. };
  1780.  
  1781. *********************************************/
  1782. /*
  1783. ** 4.x Unix time struct compatibility.
  1784. */
  1785.  
  1786. extern struct Library *SockBase;
  1787. /*
  1788. **    ss/socket.h
  1789. */
  1790.  
  1791. /*
  1792.  * Copyright (c) 1982, 1985, 1986 Regents of the University of California.
  1793.  * All rights reserved.
  1794.  *
  1795.  * Redistribution and use in source and binary forms are permitted
  1796.  * provided that the above copyright notice and this paragraph are
  1797.  * duplicated in all such forms and that any documentation,
  1798.  * advertising materials, and other materials related to such
  1799.  * distribution and use acknowledge that the software was developed
  1800.  * by the University of California, Berkeley.  The name of the
  1801.  * University may not be used to endorse or promote products derived
  1802.  * from this software without specific prior written permission.
  1803.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1804.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1805.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1806.  *
  1807.  *    @(#)socket.h    7.3 (Berkeley) 6/27/88
  1808.  */
  1809.  
  1810. /*
  1811.  * Definitions related to sockets: types, address families, options.
  1812.  */
  1813.  
  1814. /*
  1815.  * Types
  1816.  */
  1817. /*
  1818.  * Option flags per-socket.
  1819.  */
  1820. /*
  1821.  * Additional options, not kept in so_options.
  1822.  */
  1823. /*
  1824.  * Structure used for manipulating linger option.
  1825.  */
  1826. struct    linger {
  1827.     int    l_onoff;        /* option on/off */
  1828.     int    l_linger;        /* linger time */
  1829. };
  1830.  
  1831. /*
  1832.  * Level number for (get/set)sockopt() to apply to socket itself.
  1833.  */
  1834. /*
  1835.  * Address families.
  1836.  */
  1837. /*
  1838.  * Structure used by kernel to store most
  1839.  * addresses.
  1840.  */
  1841. struct sockaddr {
  1842.     u_short    sa_family;        /* address family */
  1843.     char    sa_data[14];        /* up to 14 bytes of direct address */
  1844. };
  1845.  
  1846. /*
  1847.  * Structure used by kernel to pass protocol
  1848.  * information in raw sockets.
  1849.  */
  1850. struct sockproto {
  1851.     u_short    sp_family;        /* address family */
  1852.     u_short    sp_protocol;        /* protocol */
  1853. };
  1854.  
  1855. /*
  1856.  * Protocol families, same as address families for now.
  1857.  */
  1858. /*
  1859.  * Maximum queue length specifiable by listen.
  1860.  */
  1861. /*
  1862.  * Message header for recvmsg and sendmsg calls.
  1863.  */
  1864. struct msghdr {
  1865.     caddr_t    msg_name;        /* optional address */
  1866.     int    msg_namelen;        /* size of address */
  1867.     struct    iovec *msg_iov;        /* scatter/gather array */
  1868.     int    msg_iovlen;        /* # elements in msg_iov */
  1869.     caddr_t    msg_accrights;        /* access rights sent/received */
  1870.     int    msg_accrightslen;
  1871. };
  1872.  
  1873. /*
  1874.  * Copyright (c) 1982, 1986 Regents of the University of California.
  1875.  * All rights reserved.
  1876.  *
  1877.  * Redistribution and use in source and binary forms are permitted
  1878.  * provided that the above copyright notice and this paragraph are
  1879.  * duplicated in all such forms and that any documentation,
  1880.  * advertising materials, and other materials related to such
  1881.  * distribution and use acknowledge that the software was developed
  1882.  * by the University of California, Berkeley.  The name of the
  1883.  * University may not be used to endorse or promote products derived
  1884.  * from this software without specific prior written permission.
  1885.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1886.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1887.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1888.  *
  1889.  *    @(#)in.h        7.6 (Berkeley) 6/29/88
  1890.  */
  1891.  
  1892. /*
  1893.  * Constants and structures defined by the internet system,
  1894.  * Per RFC 790, September 1981.
  1895.  */
  1896.  
  1897. /*
  1898.  * Protocols
  1899.  */
  1900. /*
  1901.  * Ports < IPPORT_RESERVED are reserved for
  1902.  * privileged processes (e.g. root).
  1903.  * Ports > IPPORT_USERRESERVED are reserved
  1904.  * for servers, not necessarily privileged.
  1905.  */
  1906. /*
  1907.  * Link numbers
  1908.  */
  1909. /*
  1910.  * Internet address (a structure for historical reasons)
  1911.  */
  1912. struct in_addr {
  1913.     u_long s_addr;
  1914. };
  1915.  
  1916. /*
  1917.  * Definitions of bits in internet address integers.
  1918.  * On subnets, the decomposition of addresses to host and net parts
  1919.  * is done according to subnet mask, not the masks here.
  1920.  */
  1921. /*
  1922.  * Socket address, internet style.
  1923.  */
  1924. struct sockaddr_in {
  1925.     short    sin_family;
  1926.     u_short sin_port;
  1927.     struct    in_addr sin_addr;
  1928.     char    sin_zero[8];
  1929. };
  1930.  
  1931. /*
  1932.  * Options for use with [gs]etsockopt at the IP level.
  1933.  */
  1934. extern struct Library *SockBase;
  1935.  
  1936. /* prototypes */
  1937.  
  1938. int accept (int, struct sockaddr *, int *);
  1939. int bind (int, struct sockaddr *, int );
  1940. void cleanup_sockets ( void ) ;
  1941. int connect (int, struct sockaddr *, int);
  1942. int dn_expand ( u_char *, u_char *, u_char *, u_char *, int );
  1943. int dn_comp ( u_char *, u_char *, int, u_char **, u_char ** );
  1944. int __dn_skipname ( u_char *, u_char * );
  1945. void endhostent ( void );
  1946. void endnetent ( void );
  1947. void endprotoent ( void );
  1948. void endpwent( void );
  1949. void endservent ( void );
  1950. int getdomainname (char *, int);
  1951. gid_t getgid (void);
  1952. int getgroups (int, gid_t *);
  1953. int get_h_errno ( void );
  1954. struct hostent *gethostbyaddr ( char *, int, int );
  1955. struct hostent *gethostbyname ( char * );
  1956. struct hostent *gethostent ( void );
  1957. int gethostname (char *, int);
  1958. char *getlogin (void);
  1959. u_long getlong ( u_char * );
  1960. struct netent *getnetbyaddr ( long, int );
  1961. struct netent *getnetbyname ( char * );
  1962. struct netent *getnetent ( void );
  1963. int getpeername ( int, struct sockaddr *, int * );
  1964. struct protoent *getprotobyname ( char * );
  1965. struct protoent *getprotobynumber ( int );
  1966. struct protoent *getprotoent ( void );
  1967. struct passwd *getpwent( void ) ;
  1968. struct passwd *getpwnam( char * );
  1969. struct passwd *getpwuid( uid_t );
  1970. struct state *get_res ( void );
  1971. struct servent *getservent ( void );
  1972. struct servent *getservbyname ( char *, char * );
  1973. struct servent *getservbyport ( u_short, char * );
  1974. u_short _getshort ( u_char * );
  1975. int getsockname ( int, struct sockaddr *, int * );
  1976. int getsockopt ( int, int, int, char *, int * );
  1977. uid_t getuid (void);
  1978. mode_t getumask (void);
  1979. short get_tz(void);
  1980. u_long inet_addr ( char * );
  1981. int inet_lnaof ( struct in_addr );
  1982. struct in_addr inet_makeaddr ( int, int );
  1983. int inet_netof ( struct in_addr );
  1984. int inet_network ( char * );
  1985. char *inet_ntoa ( struct in_addr );
  1986. int listen (int , int);
  1987. void __putshort ( u_short, u_char * );
  1988. void __putlong ( u_long, u_char * );
  1989. int rcmd( char **, u_short, char *, char *, char *, int *);
  1990. int recv(int, char *, int, int );
  1991. int recvfrom( int, char *, int, int, struct sockaddr *, int *);
  1992. int recvmsg(int, struct msghdr *, int );
  1993. int res_init ( void );
  1994. int res_mkquery ( int, char *, int, int, char *, int, struct rrec *, char *, int );
  1995. int res_query ( char *, int, int, u_char *, int );
  1996. int res_querydomain ( char *, char *, int, int, u_char *, int );
  1997. int res_send ( char *, int, char *, int );
  1998. int res_search ( char *, int, int, u_char *, int );
  1999. int s_close ( int ) ;
  2000. void s_dev_list(u_long, int);
  2001. BYTE s_getsignal ( UWORD );
  2002. int s_inherit( void * );
  2003. int s_ioctl ( int, int, char * );
  2004. void *s_release( int );
  2005. void s_dev_list(u_long, int);
  2006. int select( int, fd_set *, fd_set *, fd_set *, struct timeval *);
  2007. int selectwait (int, fd_set *, fd_set *, fd_set *, struct timeval *, long *);
  2008. int send (int, char *, int, int );
  2009. int sendto (int, char *, int, int, struct sockaddr *, int );
  2010. int sendmsg (int, struct msghdr *, int );
  2011. int setgid ( gid_t );
  2012. int set_h_errno ( int );
  2013. void sethostent ( int );
  2014. void setnetent ( int );
  2015. void setprotoent ( int );
  2016. void setpwent( int );
  2017. void setservent ( int );
  2018. int  setuid ( uid_t );
  2019. int setsockopt ( int, int, int, char *, int );
  2020. ULONG setup_sockets ( UWORD, int * );
  2021. int shutdown (int, int);
  2022. int socket( int, int, int );
  2023. int s_syslog(int, char *);
  2024. int syslogA(int, char *, int *);
  2025. int syslog(int, char *, ...);
  2026. char *strerror( int );
  2027. mode_t umask ( mode_t );
  2028. int reconfig(void) ;
  2029. void _socket( caddr_t );
  2030. void _bind( caddr_t );
  2031. void _ioctl( caddr_t );
  2032. void _listen( caddr_t );
  2033. void _accept( caddr_t );
  2034. void _connect( caddr_t );
  2035. void _sendto( caddr_t );
  2036. void _send( caddr_t );
  2037. void _sendmsg( caddr_t );
  2038. void _recvfrom( caddr_t );
  2039. void _recv( caddr_t );
  2040. void _recvmsg( caddr_t );
  2041. void _shutdown( caddr_t );
  2042. void _setsockopt( caddr_t );
  2043. void _getsockopt( caddr_t );
  2044. void _getsockname( caddr_t );
  2045. void _getpeername( caddr_t );
  2046. void _select( caddr_t );
  2047. void _networkclose( caddr_t );
  2048. void _inherit( caddr_t );
  2049. void ConfigureInetA( struct TagItem * );
  2050. void ConfigureInet( ULONG, ... );
  2051. #pragma libcall SockBase setup_sockets 1e 8102
  2052. #pragma libcall SockBase cleanup_sockets 24 0
  2053. #pragma libcall SockBase socket 2a 21003
  2054. #pragma libcall SockBase s_close 30 001
  2055. #pragma libcall SockBase s_getsignal 36 101
  2056. #pragma libcall SockBase strerror 3c 101
  2057. #pragma libcall SockBase getuid 42 0
  2058. #pragma libcall SockBase getgid 48 0
  2059. #pragma libcall SockBase getgroups 4e 8002
  2060. #pragma libcall SockBase getlogin 54 0
  2061. #pragma libcall SockBase get_tz 5a 0
  2062. #pragma libcall SockBase getdomainname 60 1902
  2063. #pragma libcall SockBase getumask 66 0
  2064. #pragma libcall SockBase umask 6c 001
  2065. #pragma libcall SockBase gethostname 72 0802
  2066. #pragma libcall SockBase sethostent 78 101
  2067. #pragma libcall SockBase endhostent 7e 0
  2068. #pragma libcall SockBase gethostent 84 0
  2069. #pragma libcall SockBase gethostbyname 8a 801
  2070. #pragma libcall SockBase gethostbyaddr 90 10803
  2071. #pragma libcall SockBase inet_addr 96 901
  2072. #pragma libcall SockBase inet_makeaddr 9c 1002
  2073. #pragma libcall SockBase inet_lnaof a2 101
  2074. #pragma libcall SockBase inet_netof a8 101
  2075. #pragma libcall SockBase inet_network ae 901
  2076. #pragma libcall SockBase inet_ntoa b4 101
  2077. #pragma libcall SockBase accept ba 98003
  2078. #pragma libcall SockBase bind c0 19003
  2079. #pragma libcall SockBase connect c6 19003
  2080. #pragma libcall SockBase s_ioctl cc 81003
  2081. #pragma libcall SockBase listen d2 1002
  2082. #pragma libcall SockBase recv d8 218004
  2083. #pragma libcall SockBase recvfrom de A9218006
  2084. #pragma libcall SockBase recvmsg e4 18003
  2085. #pragma libcall SockBase select ea 1A98005
  2086. #pragma libcall SockBase selectwait f0 21A98006
  2087. #pragma libcall SockBase send f6 918004
  2088. #pragma libcall SockBase sendto fc 39218006
  2089. #pragma libcall SockBase sendmsg 102 18003
  2090. #pragma libcall SockBase shutdown 108 1002
  2091. #pragma libcall SockBase setsockopt 10e 3821005
  2092. #pragma libcall SockBase getsockopt 114 9821005
  2093. #pragma libcall SockBase setnetent 11a 101
  2094. #pragma libcall SockBase endnetent 120 0
  2095. #pragma libcall SockBase getnetent 126 0
  2096. #pragma libcall SockBase getnetbyaddr 12c 1002
  2097. #pragma libcall SockBase getnetbyname 132 801
  2098. #pragma libcall SockBase setprotoent 138 101
  2099. #pragma libcall SockBase endprotoent 13e 0
  2100. #pragma libcall SockBase getprotoent 144 0
  2101. #pragma libcall SockBase getprotobyname 14a 801
  2102. #pragma libcall SockBase getprotobynumber 150 001
  2103. #pragma libcall SockBase setservent 156 101
  2104. #pragma libcall SockBase endservent 15c 0
  2105. #pragma libcall SockBase getservent 162 0
  2106. #pragma libcall SockBase getservbyname 168 9802
  2107. #pragma libcall SockBase getservbyport 16e 8002
  2108. #pragma libcall SockBase getpwuid 174 101
  2109. #pragma libcall SockBase getpwnam 17a 801
  2110. #pragma libcall SockBase getpwent 180 0
  2111. #pragma libcall SockBase setpwent 186 101
  2112. #pragma libcall SockBase endpwent 18c 0
  2113. #pragma libcall SockBase rcmd 192 2A981006
  2114. #pragma libcall SockBase getpeername 198 98003
  2115. #pragma libcall SockBase getsockname 19e 98003
  2116. #pragma libcall SockBase s_syslog 1a4 8002
  2117. #pragma libcall SockBase reconfig 1aa 0
  2118. #pragma libcall SockBase s_release 1b0 101
  2119. #pragma libcall SockBase s_inherit 1b6 101
  2120. #pragma libcall SockBase s_dev_list 1bc 1002
  2121. #pragma libcall SockBase syslogA 1c2 98003
  2122. #pragma libcall SockBase vsyslog 1c2 98003
  2123. #pragma tagcall SockBase syslog 1c2 98003
  2124. #pragma libcall SockBase setgid 1c8 001
  2125. #pragma libcall SockBase setuid 1ce 001
  2126. #pragma libcall SockBase dn_expand 1d4 0BA9805
  2127. #pragma libcall SockBase dn_comp 1da BA09805
  2128. #pragma libcall SockBase __dn_skipname 1e0 9802
  2129. #pragma libcall SockBase _getshort 1e6 801
  2130. #pragma libcall SockBase getlong 1ec 801
  2131. #pragma libcall SockBase __putshort 1f2 8002
  2132. #pragma libcall SockBase __putlong 1f8 8002
  2133. #pragma libcall SockBase res_send 1fe 190804
  2134. #pragma libcall SockBase res_init 204 0
  2135. #pragma libcall SockBase res_query 20a 2910805
  2136. #pragma libcall SockBase res_search 210 2910805
  2137. #pragma libcall SockBase res_querydomain 216 2A109806
  2138. #pragma libcall SockBase res_mkquery 21c 4BA39218009
  2139. #pragma libcall SockBase get_h_errno 222 0
  2140. #pragma libcall SockBase set_h_errno 228 001
  2141. #pragma libcall SockBase get_res 22e 0
  2142. #pragma libcall SockBase _socket 234 101
  2143. #pragma libcall SockBase _bind 23a 101
  2144. #pragma libcall SockBase _ioctl 240 101
  2145. #pragma libcall SockBase _listen 246 101
  2146. #pragma libcall SockBase _accept 24c 101
  2147. #pragma libcall SockBase _connect 252 101
  2148. #pragma libcall SockBase _sendto  258 101
  2149. #pragma libcall SockBase _send 25e 101
  2150. #pragma libcall SockBase _sendmsg 264 101
  2151. #pragma libcall SockBase _recvfrom 26a 101
  2152. #pragma libcall SockBase _recv 270 101
  2153. #pragma libcall SockBase _recvmsg 276 101
  2154. #pragma libcall SockBase _shutdown 27c 101
  2155. #pragma libcall SockBase _setsockopt 282 101
  2156. #pragma libcall SockBase _getsockopt 288 101
  2157. #pragma libcall SockBase _getsockname 28e 101
  2158. #pragma libcall SockBase _getpeername 294 101
  2159. #pragma libcall SockBase _select 29a 101
  2160. #pragma libcall SockBase _networkclose 2a0 101
  2161. #pragma libcall SockBase _inherit 2a6 101
  2162. #pragma libcall SockBase ConfigureInetA 2ac 801
  2163. #pragma tagcall SockBase ConfigureInet 2ac 801
  2164. #pragma libcall SockBase s_dup 2b2 001
  2165. #pragma libcall SockBase s_dup2 2b8 1002
  2166. /*
  2167.  * Copyright (c) 1980, 1983, 1988 Regents of the University of California.
  2168.  * All rights reserved.
  2169.  *
  2170.  * Redistribution and use in source and binary forms are permitted
  2171.  * provided that the above copyright notice and this paragraph are
  2172.  * duplicated in all such forms and that any documentation,
  2173.  * advertising materials, and other materials related to such
  2174.  * distribution and use acknowledge that the software was developed
  2175.  * by the University of California, Berkeley.  The name of the
  2176.  * University may not be used to endorse or promote products derived
  2177.  * from this software without specific prior written permission.
  2178.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  2179.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  2180.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  2181.  *
  2182.  *    @(#)netdb.h    5.10 (Berkeley) 6/27/88
  2183.  */
  2184.  
  2185. /*
  2186.  * Structures returned by network
  2187.  * data base library.  All addresses
  2188.  * are supplied in host order, and
  2189.  * returned in network order (suitable
  2190.  * for use in system calls).
  2191.  */
  2192. struct    hostent {
  2193.     char    *h_name;    /* official name of host */
  2194.     char    **h_aliases;    /* alias list */
  2195.     int    h_addrtype;    /* host address type */
  2196.     int    h_length;    /* length of address */
  2197.     char    **h_addr_list;    /* list of addresses from name server */
  2198. };
  2199.  
  2200. /*
  2201.  * Assumption here is that a network number
  2202.  * fits in 32 bits -- probably a poor one.
  2203.  */
  2204. struct    netent {
  2205.     char        *n_name;    /* official name of net */
  2206.     char        **n_aliases;    /* alias list */
  2207.     int        n_addrtype;    /* net address type */
  2208.     unsigned long    n_net;        /* network # */
  2209. };
  2210.  
  2211. struct    servent {
  2212.     char    *s_name;    /* official service name */
  2213.     char    **s_aliases;    /* alias list */
  2214.     int    s_port;        /* port # */
  2215.     char    *s_proto;    /* protocol to use */
  2216. };
  2217.  
  2218. struct    protoent {
  2219.     char    *p_name;    /* official protocol name */
  2220.     char    **p_aliases;    /* alias list */
  2221.     int    p_proto;    /* protocol # */
  2222. };
  2223.  
  2224. struct rpcent {
  2225.     char    *r_name;    /* name of server for this rpc program */
  2226.     char    **r_aliases;    /* alias list */
  2227.     long    r_number;    /* rpc program number */
  2228. };
  2229.  
  2230. struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
  2231.  
  2232. /*
  2233. struct hostent    *gethostbyname(), *gethostbyaddr(), *gethostent();
  2234. struct netent    *getnetbyname(), *getnetbyaddr(), *getnetent();
  2235. struct servent    *getservbyname(), *getservbyport(), *getservent();
  2236. struct protoent    *getprotobyname(), *getprotobynumber(), *getprotoent();
  2237. */
  2238.  
  2239.  
  2240. /*
  2241.  * Error return codes from gethostbyname() and gethostbyaddr()
  2242.  * (left in extern int h_errno).
  2243.  */
  2244.  
  2245. /*
  2246.  
  2247. Defaults
  2248.  
  2249.   INCLUDE FILES FOR TCP
  2250.  
  2251.  */
  2252. /*
  2253.  
  2254.   MACROS FOR MANIPULATING MASKS FOR SELECT()
  2255.  
  2256.  */
  2257. /*      Display a message and get the input
  2258. **
  2259. **      On entry,
  2260. **              Msg is the message.
  2261. **
  2262. **      On exit,
  2263. **              Return value is malloc'd string which must be freed.
  2264. */
  2265. extern char * HTPrompt ( char * Msg,  char * deflt);
  2266. extern char * HTPromptPassword ( char * Msg);
  2267.  
  2268.  
  2269. /*      Display a message, don't wait for input
  2270. **
  2271. **      On entry,
  2272. **              The input is a list of parameters for printf.
  2273. */
  2274. extern void HTAlert ( char * Msg);
  2275.  
  2276.  
  2277. /*      Display a progress message for information (and diagnostics) only
  2278. **
  2279. **      On entry,
  2280. **              The input is a list of parameters for printf.
  2281. */
  2282. extern void HTProgress ( char * Msg);
  2283. extern int HTCheckActiveIcon (int twirl);
  2284. extern void HTClearActiveIcon (void);
  2285.  
  2286.  
  2287. /*      Display a message, then wait for 'yes' or 'no'.
  2288. **
  2289. **      On entry,
  2290. **              Takes a list of parameters for printf.
  2291. **
  2292. **      On exit,
  2293. **              If the user enters 'YES', returns TRUE, returns FALSE
  2294. **              otherwise.
  2295. */
  2296. extern BOOLEAN HTConfirm ( char * Msg);
  2297. /*
  2298.  
  2299.     */
  2300.  
  2301. /*                                            Utilities for the Authorization parts of libwww
  2302.              COMMON PARTS OF AUTHORIZATION MODULE TO BOTH SERVER AND BROWSER
  2303.                                              
  2304.    This module is the interface to the common parts of Access Authorization (AA) package
  2305.    for both server and browser. Important to know about memory allocation:
  2306.    
  2307.    Routines in this module use dynamic allocation, but free automatically all the memory
  2308.    reserved by them.
  2309.    
  2310.    Therefore the caller never has to (and never should) free() any object returned by
  2311.    these functions.
  2312.    
  2313.    Therefore also all the strings returned by this package are only valid until the next
  2314.    call to the same function is made. This approach is selected, because of the nature of
  2315.    access authorization: no string returned by the package needs to be valid longer than
  2316.    until the next call.
  2317.    
  2318.    This also makes it easy to plug the AA package in: you don't have to ponder whether to
  2319.    free() something here or is it done somewhere else (because it is always done somewhere
  2320.    else).
  2321.    
  2322.    The strings that the package needs to store are copied so the original strings given as
  2323.    parameters to AA functions may be freed or modified with no side effects.
  2324.    
  2325.    Also note: The AA package does not free() anything else than what it has itself
  2326.    allocated.
  2327.    
  2328.  */
  2329.  
  2330. /*                                                    Utitlity macros for the W3 code library
  2331.                                   MACROS FOR GENERAL USE
  2332.                                              
  2333.    Generates: HTUtils.h
  2334.    
  2335.    See also: the system dependent file "tcp.h"
  2336.    
  2337.  */
  2338.  
  2339. /*
  2340.  
  2341.    end of utilities  */
  2342.  
  2343. /*  */
  2344.  
  2345. /*              List object
  2346. **
  2347. **      The list object is a generic container for storing collections
  2348. **      of things in order.
  2349. */
  2350. /*
  2351.  
  2352.     */
  2353.  
  2354. /*          System dependencies in the W3 library
  2355.                    SYSTEM DEPENDENCIES
  2356.  
  2357.    System-system differences for TCP include files and macros. This
  2358.    file includes for each system the files necessary for network and
  2359.    file I/O.
  2360.  
  2361.   AUTHORS
  2362.  
  2363.   TBL             Tim Berners-Lee, W3 project, CERN, <timbl@info.cern.ch>
  2364.   EvA              Eelco van Asperen <evas@cs.few.eur.nl>
  2365.   MA              Marc Andreessen NCSA
  2366.   AT              Aleksandar Totic <atotic@ncsa.uiuc.edu>
  2367.   SCW              Susan C. Weber <sweber@kyle.eitech.com>
  2368.   MJW              Michael J Witbrock <witbrock@cmu.edu>
  2369.   MWM              Mike Meyer  <mwm@contessa.phone.net>
  2370.  
  2371.   HISTORY:
  2372.   22 Feb 91          Written (TBL) as part of the WWW library.
  2373.   16 Jan 92          PC code from EvA
  2374.   22 Apr 93          Merged diffs bits from xmosaic release
  2375.   29 Apr 93          Windows/NT code from SCW
  2376.  
  2377.   Much of the cross-system portability stuff has been intentionally
  2378.   REMOVED from this version of the library by Marc A in order to
  2379.   discourage attempts to make "easy" ports of Mosaic for X to non-Unix
  2380.   platforms.  The library needs to be rewritten from the ground up; in
  2381.   the meantime, Unix is *all* we support or intend to support with
  2382.   this set of source code.
  2383.  
  2384. */
  2385.  
  2386. /*
  2387.  
  2388. Default filenames
  2389.  
  2390.  */
  2391. /*
  2392. ** Numeric constants
  2393. */
  2394.                                         /* (encrypted, so really only 3*8)*/
  2395.                                         /* protection setup file          */
  2396.                                         /* patname to allow               */
  2397.  
  2398. /*
  2399. ** Helpful macros
  2400. */
  2401. /*
  2402.  
  2403. Datatype definitions
  2404.  
  2405.   HTAASCHEME
  2406.   
  2407.    The enumeration HTAAScheme represents the possible authentication schemes used by the
  2408.    WWW Access Authorization.
  2409.    
  2410.  */
  2411.  
  2412. typedef enum {
  2413.     HTAA_UNKNOWN,
  2414.     HTAA_NONE,
  2415.     HTAA_BASIC,
  2416.     HTAA_PUBKEY,
  2417.     HTAA_KERBEROS_V4,
  2418.     HTAA_KERBEROS_V5,
  2419.     HTAA_MAX_SCHEMES /* THIS MUST ALWAYS BE LAST! Number of schemes */
  2420. } HTAAScheme;
  2421.  
  2422. /*
  2423.  
  2424.   ENUMERATION TO REPRESENT HTTP METHODS
  2425.   
  2426.  */
  2427.  
  2428. typedef enum {
  2429.     METHOD_UNKNOWN,
  2430.     METHOD_GET,
  2431.     METHOD_PUT
  2432. } HTAAMethod;
  2433.  
  2434. /*
  2435.  
  2436. Authentication Schemes
  2437.  
  2438.  */
  2439.  
  2440. /* PUBLIC                                               HTAAScheme_enum()
  2441. **              TRANSLATE SCHEME NAME TO A SCHEME ENUMERATION
  2442. ** ON ENTRY:
  2443. **      name            is a string representing the scheme name.
  2444. **
  2445. ** ON EXIT:
  2446. **      returns         the enumerated constant for that scheme.
  2447. */
  2448.  HTAAScheme HTAAScheme_enum ( char* name);
  2449.  
  2450.  
  2451. /* PUBLIC                                               HTAAScheme_name()
  2452. **                      GET THE NAME OF A GIVEN SCHEME
  2453. ** ON ENTRY:
  2454. **      scheme          is one of the scheme enum values:
  2455. **                      HTAA_NONE, HTAA_BASIC, HTAA_PUBKEY, ...
  2456. **
  2457. ** ON EXIT:
  2458. **      returns         the name of the scheme, i.e.
  2459. **                      "none", "basic", "pubkey", ...
  2460. */
  2461.  char *HTAAScheme_name (HTAAScheme scheme);
  2462.  
  2463. /*
  2464.  
  2465. Methods
  2466.  
  2467.  */
  2468.  
  2469. /* PUBLIC                                                   HTAAMethod_enum()
  2470. **              TRANSLATE METHOD NAME INTO AN ENUMERATED VALUE
  2471. ** ON ENTRY:
  2472. **      name            is the method name to translate.
  2473. **
  2474. ** ON EXIT:
  2475. **      returns         HTAAMethod enumerated value corresponding
  2476. **                      to the given name.
  2477. */
  2478.  HTAAMethod HTAAMethod_enum ( char * name);
  2479.  
  2480.  
  2481. /* PUBLIC                                               HTAAMethod_name()
  2482. **                      GET THE NAME OF A GIVEN METHOD
  2483. ** ON ENTRY:
  2484. **      method          is one of the method enum values:
  2485. **                      METHOD_GET, METHOD_PUT, ...
  2486. **
  2487. ** ON EXIT:
  2488. **      returns         the name of the scheme, i.e.
  2489. **                      "GET", "PUT", ...
  2490. */
  2491.  char *HTAAMethod_name (HTAAMethod method);
  2492.  
  2493.  
  2494. /* PUBLIC                                               HTAAMethod_inList()
  2495. **              IS A METHOD IN A LIST OF METHOD NAMES
  2496. ** ON ENTRY:
  2497. **      method          is the method to look for.
  2498. **      list            is a list of method names.
  2499. **
  2500. ** ON EXIT:
  2501. **      returns         YES, if method was found.
  2502. **                      NO, if not found.
  2503. */
  2504.  BOOLEAN HTAAMethod_inList 
  2505. (HTAAMethod method, HTList * list);
  2506. /*
  2507.  
  2508. Match Template Against Filename
  2509.  
  2510.  */
  2511.  
  2512. /* PUBLIC                                               HTAA_templateMatch()
  2513. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  2514. **                 WITH ONE WILDCARD * IN THE TEMPLATE
  2515. ** NOTE:
  2516. **      This is essentially the same code as in HTRules.c, but it
  2517. **      cannot be used because it is embedded in between other code.
  2518. **      (In fact, HTRules.c should use this routine, but then this
  2519. **       routine would have to be more sophisticated... why is life
  2520. **       sometimes so hard...)
  2521. **
  2522. ** ON ENTRY:
  2523. **      template        is a template string to match the file name
  2524. **                      agaist, may contain a single wildcard
  2525. **                      character * which matches zero or more
  2526. **                      arbitrary characters.
  2527. **      filename        is the filename (or pathname) to be matched
  2528. **                      agaist the template.
  2529. **
  2530. ** ON EXIT:
  2531. **      returns         YES, if filename matches the template.
  2532. **                      NO, otherwise.
  2533. */
  2534.  BOOLEAN HTAA_templateMatch 
  2535. ( char * template,  char * filename);
  2536.  
  2537.  
  2538. /* PUBLIC                                       HTAA_makeProtectionTemplate()
  2539. **              CREATE A PROTECTION TEMPLATE FOR THE FILES
  2540. **              IN THE SAME DIRECTORY AS THE GIVEN FILE
  2541. **              (Used by server if there is no fancier way for
  2542. **              it to tell the client, and by browser if server
  2543. **              didn't send WWW-ProtectionTemplate: field)
  2544. ** ON ENTRY:
  2545. **      docname is the document pathname (from URL).
  2546. **
  2547. ** ON EXIT:
  2548. **      returns a template matching docname, and other files
  2549. **              files in that directory.
  2550. **
  2551. **              E.g.  /foo/bar/x.html  =>  /foo/bar/ *
  2552. **                                                  ^
  2553. **                              Space only to prevent it from
  2554. **                              being a comment marker here,
  2555. **                              there really isn't any space.
  2556. */
  2557.  char *HTAA_makeProtectionTemplate ( char * docname);
  2558. /*
  2559.  
  2560. MIME Argument List Parser
  2561.  
  2562.  */
  2563.  
  2564.  
  2565. /* PUBLIC                                               HTAA_parseArgList()
  2566. **              PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD
  2567. ** ON ENTRY:
  2568. **      str     is a comma-separated list:
  2569. **
  2570. **                      item, item, item
  2571. **              where
  2572. **                      item ::= value
  2573. **                             | name=value
  2574. **                             | name="value"
  2575. **
  2576. **              Leading and trailing whitespace is ignored
  2577. **              everywhere except inside quotes, so the following
  2578. **              examples are equal:
  2579. **
  2580. **                      name=value,foo=bar
  2581. **                       name="value",foo="bar"
  2582. **                        name = value ,  foo = bar
  2583. **                         name = "value" ,  foo = "bar"
  2584. **
  2585. ** ON EXIT:
  2586. **      returns a list of name-value pairs (actually HTAssocList*).
  2587. **              For items with no name, just value, the name is
  2588. **              the number of order number of that item. E.g.
  2589. **              "1" for the first, etc.
  2590. */
  2591.  HTList *HTAA_parseArgList (char * str);
  2592.  
  2593. /*
  2594.  
  2595. Header Line Reader
  2596.  
  2597.  */
  2598.  
  2599. /* PUBLIC                                               HTAA_setupReader()
  2600. **              SET UP HEADER LINE READER, i.e. give
  2601. **              the already-read-but-not-yet-processed
  2602. **              buffer of text to be read before more
  2603. **              is read from the socket.
  2604. ** ON ENTRY:
  2605. **      start_of_headers is a pointer to a buffer containing
  2606. **                      the beginning of the header lines
  2607. **                      (rest will be read from a socket).
  2608. **      length          is the number of valid characters in
  2609. **                      'start_of_headers' buffer.
  2610. **      soc             is the socket to use when start_of_headers
  2611. **                      buffer is used up.
  2612. ** ON EXIT:
  2613. **      returns         nothing.
  2614. **                      Subsequent calls to HTAA_getUnfoldedLine()
  2615. **                      will use this buffer first and then
  2616. **                      proceed to read from socket.
  2617. */
  2618.  void HTAA_setupReader 
  2619. (char * start_of_headers, int length, int soc);
  2620.  
  2621.  
  2622. /* PUBLIC                                               HTAA_getUnfoldedLine()
  2623. **              READ AN UNFOLDED HEADER LINE FROM SOCKET
  2624. ** ON ENTRY:
  2625. **      HTAA_setupReader must absolutely be called before
  2626. **      this function to set up internal buffer.
  2627. **
  2628. ** ON EXIT:
  2629. **      returns a newly-allocated character string representing
  2630. **              the read line.  The line is unfolded, i.e.
  2631. **              lines that begin with whitespace are appended
  2632. **              to current line.  E.g.
  2633. **
  2634. **                      Field-Name: Blaa-Blaa
  2635. **                       This-Is-A-Continuation-Line
  2636. **                       Here-Is_Another
  2637. **
  2638. **              is seen by the caller as:
  2639. **
  2640. **      Field-Name: Blaa-Blaa This-Is-A-Continuation-Line Here-Is_Another
  2641. **
  2642. */
  2643.  char *HTAA_getUnfoldedLine (void);
  2644.  
  2645. /*
  2646.  
  2647.    End of file HTAAUtil.h. */
  2648.  
  2649. /*                       ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS
  2650.                                              
  2651.    Lookups from assosiation list are not case-sensitive.
  2652.    
  2653.  */
  2654.  
  2655. /*                                                    Utitlity macros for the W3 code library
  2656.                                   MACROS FOR GENERAL USE
  2657.                                              
  2658.    Generates: HTUtils.h
  2659.    
  2660.    See also: the system dependent file "tcp.h"
  2661.    
  2662.  */
  2663.  
  2664. /*
  2665.  
  2666.    end of utilities  */
  2667.  
  2668. /*  */
  2669.  
  2670. /*              List object
  2671. **
  2672. **      The list object is a generic container for storing collections
  2673. **      of things in order.
  2674. */
  2675. /*
  2676.  
  2677.     */
  2678.  
  2679.  
  2680.  
  2681. typedef HTList HTAssocList;
  2682.  
  2683. typedef struct {
  2684.     char * name;
  2685.     char * value;
  2686. } HTAssoc;
  2687.  
  2688.  
  2689.  HTAssocList *HTAssocList_new (void);
  2690.  void HTAssocList_delete (HTAssocList * alist);
  2691.  
  2692.  void HTAssocList_add 
  2693. (HTAssocList * alist,  char * name,  char * value);
  2694.  
  2695.  char *HTAssocList_lookup 
  2696. (HTAssocList * alist,  char * name);
  2697.  
  2698. /*
  2699.  
  2700.    End of file HTAssoc.h.  */
  2701.  
  2702. /*                          BROWSER SIDE ACCESS AUTHORIZATION MODULE
  2703.                                              
  2704.    This module is the browser side interface to Access Authorization (AA) package.  It
  2705.    contains code only for browser.
  2706.    
  2707.    Important to know about memory allocation:
  2708.    
  2709.    Routines in this module use dynamic allocation, but free automatically all the memory
  2710.    reserved by them.
  2711.    
  2712.    Therefore the caller never has to (and never should) free() any object returned by
  2713.    these functions.
  2714.    
  2715.    Therefore also all the strings returned by this package are only valid until the next
  2716.    call to the same function is made. This approach is selected, because of the nature of
  2717.    access authorization: no string returned by the package needs to be valid longer than
  2718.    until the next call.
  2719.    
  2720.    This also makes it easy to plug the AA package in: you don't have to ponder whether to
  2721.    free()something here or is it done somewhere else (because it is always done somewhere
  2722.    else).
  2723.    
  2724.    The strings that the package needs to store are copied so the original strings given as
  2725.    parameters to AA functions may be freed or modified with no side effects.
  2726.    
  2727.    Also note:The AA package does not free() anything else than what it has itself
  2728.    allocated.
  2729.    
  2730.  */
  2731.  
  2732. /*                                                    Utitlity macros for the W3 code library
  2733.                                   MACROS FOR GENERAL USE
  2734.                                              
  2735.    Generates: HTUtils.h
  2736.    
  2737.    See also: the system dependent file "tcp.h"
  2738.    
  2739.  */
  2740.  
  2741. /*
  2742.  
  2743.    end of utilities  */
  2744.  
  2745. /*                                            Utilities for the Authorization parts of libwww
  2746.              COMMON PARTS OF AUTHORIZATION MODULE TO BOTH SERVER AND BROWSER
  2747.                                              
  2748.    This module is the interface to the common parts of Access Authorization (AA) package
  2749.    for both server and browser. Important to know about memory allocation:
  2750.    
  2751.    Routines in this module use dynamic allocation, but free automatically all the memory
  2752.    reserved by them.
  2753.    
  2754.    Therefore the caller never has to (and never should) free() any object returned by
  2755.    these functions.
  2756.    
  2757.    Therefore also all the strings returned by this package are only valid until the next
  2758.    call to the same function is made. This approach is selected, because of the nature of
  2759.    access authorization: no string returned by the package needs to be valid longer than
  2760.    until the next call.
  2761.    
  2762.    This also makes it easy to plug the AA package in: you don't have to ponder whether to
  2763.    free() something here or is it done somewhere else (because it is always done somewhere
  2764.    else).
  2765.    
  2766.    The strings that the package needs to store are copied so the original strings given as
  2767.    parameters to AA functions may be freed or modified with no side effects.
  2768.    
  2769.    Also note: The AA package does not free() anything else than what it has itself
  2770.    allocated.
  2771.    
  2772.  */
  2773.  
  2774. /*
  2775.  
  2776.    End of file HTAAUtil.h. */
  2777.  
  2778.  
  2779.  
  2780. /*
  2781.  
  2782. Routines for Browser Side Recording of AA Info
  2783.  
  2784.    Most of the browser-side AA is done by the following two functions (which are called
  2785.    from file HTTP.c so the browsers using libwww only need to be linked with the new
  2786.    library and not be changed at all):
  2787.    
  2788.       HTAA_composeAuth() composes the Authorization: line contents, if the AA package
  2789.       thinks that the given document is protected. Otherwise this function returns NULL.
  2790.       This function also calls the functions HTPrompt(),HTPromptPassword() and HTConfirm()
  2791.       to get the username, password and some confirmation from the user.
  2792.       
  2793.       HTAA_shouldRetryWithAuth() determines whether to retry the request with AA or with a
  2794.       new AA (in case username or password was misspelled).
  2795.  
  2796.       HTAA_TryWithAuth() sets up everything for an automatic first try with authentication.
  2797.  
  2798.       HTAA_ClearAuth() clears the currently allocated authentication record.
  2799.       
  2800.  */
  2801.  
  2802. /* PUBLIC                                               HTAA_composeAuth()
  2803. **
  2804. **      COMPOSE THE ENTIRE AUTHORIZATION HEADER LINE IF WE
  2805. **      ALREADY KNOW, THAT THE HOST MIGHT REQUIRE AUTHORIZATION
  2806. **
  2807. ** ON ENTRY:
  2808. **      hostname        is the hostname of the server.
  2809. **      portnumber      is the portnumber in which the server runs.
  2810. **      docname         is the pathname of the document (as in URL)
  2811. **
  2812. ** ON EXIT:
  2813. **      returns NULL, if no authorization seems to be needed, or
  2814. **              if it is the entire Authorization: line, e.g.
  2815. **
  2816. **                 "Authorization: basic username:password"
  2817. **
  2818. **              As usual, this string is automatically freed.
  2819. */
  2820.  char *HTAA_composeAuth 
  2821. ( char * hostname,  int portnumber,  char * docname);
  2822.  
  2823.  
  2824. /* BROWSER PUBLIC                               HTAA_shouldRetryWithAuth()
  2825. **
  2826. **              DETERMINES IF WE SHOULD RETRY THE SERVER
  2827. **              WITH AUTHORIZATION
  2828. **              (OR IF ALREADY RETRIED, WITH A DIFFERENT
  2829. **              USERNAME AND/OR PASSWORD (IF MISSPELLED))
  2830. ** ON ENTRY:
  2831. **      start_of_headers is the first block already read from socket,
  2832. **                      but status line skipped; i.e. points to the
  2833. **                      start of the header section.
  2834. **      length          is the remaining length of the first block.
  2835. **      soc             is the socket to read the rest of server reply.
  2836. **
  2837. **                      This function should only be called when
  2838. **                      server has replied with a 401 (Unauthorized)
  2839. **                      status code.
  2840. ** ON EXIT:
  2841. **      returns         YES, if connection should be retried.
  2842. **                           The node containing all the necessary
  2843. **                           information is
  2844. **                              * either constructed if it does not exist
  2845. **                              * or password is reset to NULL to indicate
  2846. **                                that username and password should be
  2847. **                                reprompted when composing Authorization:
  2848. **                                field (in function HTAA_composeAuth()).
  2849. **                      NO, otherwise.
  2850. */
  2851.  BOOLEAN HTAA_shouldRetryWithAuth 
  2852. (char * start_of_headers, int length, int soc);
  2853.  
  2854.  
  2855. /*
  2856.  
  2857.    End of file HTAABrow.h.  */
  2858.  
  2859. /*                              ENCODING TO PRINTABLE CHARACTERS
  2860.                                              
  2861.    File module provides functions HTUU_encode() and HTUU_decode() which convert a buffer
  2862.    of bytes to/from RFC 1113 printable encoding format. This technique is similar to the
  2863.    familiar Unix uuencode format in that it maps 6 binary bits to one ASCII character (or
  2864.    more aptly, 3 binary bytes to 4 ASCII characters).  However, RFC 1113 does not use the
  2865.    same mapping to printable characters as uuencode.
  2866.    
  2867.  */
  2868.  
  2869. /*                                                    Utitlity macros for the W3 code library
  2870.                                   MACROS FOR GENERAL USE
  2871.                                              
  2872.    Generates: HTUtils.h
  2873.    
  2874.    See also: the system dependent file "tcp.h"
  2875.    
  2876.  */
  2877.  
  2878. /*
  2879.  
  2880.    end of utilities  */
  2881.  
  2882.  
  2883.  int HTUU_encode 
  2884. (unsigned char *bufin, unsigned int nbytes, char *bufcoded);
  2885.  
  2886.  int HTUU_decode 
  2887. (char *bufcoded, unsigned char *bufplain, int outbufsize);
  2888.  
  2889. /*
  2890.  
  2891.    End of file.  */
  2892.  
  2893.  
  2894.  
  2895.  
  2896. /*
  2897. ** Local datatype definitions
  2898. **
  2899. ** HTAAServer contains all the information about one server.
  2900. */
  2901. typedef struct {
  2902.  
  2903.     char *    hostname;    /* Host's name            */
  2904.     int        portnumber;    /* Port number            */
  2905.     HTList *    setups;        /* List of protection setups    */
  2906.                                 /* on this server; i.e. valid    */
  2907.                                 /* authentication schemes and    */
  2908.                                 /* templates when to use them.    */
  2909.                                 /* This is actually a list of    */
  2910.                                 /* HTAASetup objects.        */
  2911.     HTList *    realms;        /* Information about passwords    */
  2912. } HTAAServer;
  2913.  
  2914.  
  2915. /*
  2916. ** HTAASetup contains information about one server's one
  2917. ** protected tree of documents.
  2918. */
  2919. typedef struct {
  2920.     HTAAServer *server;        /* Which server serves this tree         */
  2921.     char *    template;    /* Template for this tree             */
  2922.     HTList *    valid_schemes;    /* Valid authentic.schemes                */
  2923.     HTAssocList**scheme_specifics;/* Scheme specific params             */
  2924.     BOOLEAN    retry;        /* Failed last time -- reprompt (or whatever)*/
  2925. } HTAASetup;
  2926.  
  2927.  
  2928. /*
  2929. ** Information about usernames and passwords in
  2930. ** Basic and Pubkey authentication schemes;
  2931. */
  2932. typedef struct {
  2933.     char *    realmname;    /* Password domain name        */
  2934.     char *    username;    /* Username in that domain    */
  2935.     char *    password;    /* Corresponding password    */
  2936. } HTAARealm;
  2937.  
  2938.  
  2939.  
  2940. /*
  2941. ** Module-wide global variables
  2942. */
  2943.  
  2944. static HTList *server_table    = 0L;    /* Browser's info about servers         */
  2945. static char *secret_key    = 0L;    /* Browser's latest secret key       */
  2946. static HTAASetup *current_setup= 0L;    /* The server setup we are currently */
  2947.                                         /* talking to                 */
  2948. static char *current_hostname    = 0L;    /* The server's name and portnumber  */
  2949. static int current_portnumber    = 80;    /* where we are currently trying to  */
  2950.                                         /* connect.                 */
  2951. static char *current_docname    = 0L;    /* The document's name we are        */
  2952.                                         /* trying to access.             */
  2953.  
  2954. /**************************** HTAAServer ***********************************/
  2955.  
  2956.  
  2957. /* PRIVATE                        HTAAServer_new()
  2958. **        ALLOCATE A NEW NODE TO HOLD SERVER INFO
  2959. **        AND ADD IT TO THE LIST OF SERVERS
  2960. ** ON ENTRY:
  2961. **    hostname    is the name of the host that the server
  2962. **            is running in.
  2963. **    portnumber    is the portnumber which the server listens.
  2964. **
  2965. ** ON EXIT:
  2966. **    returns        the newly-allocated node with all the strings
  2967. **            duplicated.
  2968. **            Strings will be automatically freed by
  2969. **            the function HTAAServer_delete(), which also
  2970. **            frees the node itself.
  2971. */
  2972. static HTAAServer *HTAAServer_new 
  2973. ( char* hostname, int portnumber)
  2974. {
  2975.     HTAAServer *server;
  2976.  
  2977.     if (!(server = (HTAAServer *)malloc(sizeof(HTAAServer))))
  2978.     { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "HTAAServer_new"); exit(1);};
  2979.  
  2980.     server->hostname    = 0L;
  2981.     server->portnumber    = (portnumber > 0 ? portnumber : 80);
  2982.     server->setups    = HTList_new();
  2983.     server->realms    = HTList_new();
  2984.  
  2985.     if (hostname) HTSACopy (&(server->hostname), hostname);
  2986.  
  2987.     if (!server_table) server_table = HTList_new();
  2988.     
  2989.     HTList_addObject(server_table, (void*)server);
  2990.  
  2991.     return server;
  2992. }
  2993.  
  2994.  
  2995. /* PRIVATE                        HTAAServer_delete()
  2996. **
  2997. **    DELETE THE ENTRY FOR THE SERVER FROM THE HOST TABLE,
  2998. **    AND FREE THE MEMORY USED BY IT.
  2999. **
  3000. ** ON ENTRY:
  3001. **    killme        points to the HTAAServer to be freed.
  3002. **
  3003. ** ON EXIT:
  3004. **    returns        nothing.
  3005. */
  3006. /* PRIVATE                        HTAAServer_lookup()
  3007. **        LOOK UP SERVER BY HOSTNAME AND PORTNUMBER
  3008. ** ON ENTRY:
  3009. **    hostname    obvious.
  3010. **    portnumber    if non-positive defaults to 80.
  3011. **
  3012. **    Looks up the server in the module-global server_table.
  3013. **
  3014. ** ON EXIT:
  3015. **    returns        pointer to a HTAAServer structure
  3016. **            representing the looked-up server.
  3017. **            NULL, if not found.
  3018. */
  3019. static HTAAServer *HTAAServer_lookup 
  3020. ( char * hostname, int portnumber)
  3021. {
  3022.     if (hostname) {
  3023.     HTList *cur = server_table;
  3024.     HTAAServer *server;
  3025.  
  3026.     if (portnumber <= 0) portnumber = 80;
  3027.  
  3028.     while (0L != (server = (HTAAServer*)(cur && (cur = cur ->next) ? cur ->object : 0L))) {
  3029.         if (server->portnumber == portnumber  &&
  3030.         0== __builtin_strcmp(server->hostname,hostname))
  3031.         return server;
  3032.     }
  3033.     }
  3034.     return 0L;    /* NULL parameter, or not found */
  3035. }
  3036.  
  3037.  
  3038.  
  3039.  
  3040. /*************************** HTAASetup *******************************/    
  3041.  
  3042.  
  3043. /* PRIVATE                        HTAASetup_lookup()
  3044. **    FIGURE OUT WHICH AUTHENTICATION SETUP THE SERVER
  3045. **    IS USING FOR A GIVEN FILE ON A GIVEN HOST AND PORT
  3046. **
  3047. ** ON ENTRY:
  3048. **    hostname    is the name of the server host machine.
  3049. **    portnumber    is the port that the server is running in.
  3050. **    docname        is the (URL-)pathname of the document we
  3051. **            are trying to access.
  3052. **
  3053. **     This function goes through the information known about
  3054. **    all the setups of the server, and finds out if the given
  3055. **    filename resides in one of the protected directories.
  3056. **
  3057. ** ON EXIT:
  3058. **    returns        NULL if no match.
  3059. **            Otherwise, a HTAASetup structure representing
  3060. **            the protected server setup on the corresponding
  3061. **            document tree.
  3062. **            
  3063. */
  3064. static HTAASetup *HTAASetup_lookup 
  3065. ( char * hostname, int portnumber,  char * docname)
  3066. {
  3067.     HTAAServer *server;
  3068.     HTAASetup *setup;
  3069.  
  3070.     if (portnumber <= 0) portnumber = 80;
  3071.  
  3072.     if (hostname && docname && *hostname && *docname &&
  3073.     0L != (server = HTAAServer_lookup(hostname, portnumber))) {
  3074.  
  3075.     HTList *cur = server->setups;
  3076.  
  3077.     if ((WWW_TraceFlag)) fprintf((&__iob[2]), "%s (%s:%d:%s)\n",
  3078.                "HTAASetup_lookup: resolving setup for",
  3079.                hostname, portnumber, docname);
  3080.  
  3081.     while (0L != (setup = (HTAASetup*)(cur && (cur = cur ->next) ? cur ->object : 0L))) {
  3082.         if (HTAA_templateMatch(setup->template, docname)) {
  3083.         if ((WWW_TraceFlag)) fprintf((&__iob[2]), "%s `%s' %s `%s'\n",
  3084.                    "HTAASetup_lookup:", docname,
  3085.                    "matched template", setup->template);
  3086.         return setup;
  3087.         }
  3088.         else if ((WWW_TraceFlag)) fprintf((&__iob[2]), "%s `%s' %s `%s'\n",
  3089.                     "HTAASetup_lookup:", docname,
  3090.                     "did NOT match template", setup->template);
  3091.     } /* while setups remain */
  3092.     } /* if valid parameters and server found */
  3093.  
  3094.     if ((WWW_TraceFlag)) fprintf((&__iob[2]), "%s `%s' %s\n",
  3095.                "HTAASetup_lookup: No template matched",
  3096.                (docname ? docname : "(null)"),
  3097.                "(so probably not protected)");
  3098.  
  3099.     return 0L;    /* NULL in parameters, or not found */
  3100. }
  3101.  
  3102.  
  3103.  
  3104.  
  3105. /* PRIVATE                        HTAASetup_new()
  3106. **            CREATE A NEW SETUP NODE
  3107. ** ON ENTRY:
  3108. **    server        is a pointer to a HTAAServer structure
  3109. **            to which this setup belongs.
  3110. **    template    documents matching this template
  3111. **            are protected according to this setup.
  3112. **    valid_schemes    a list containing all valid authentication
  3113. **            schemes for this setup.
  3114. **            If NULL, all schemes are disallowed.
  3115. **    scheme_specifics is an array of assoc lists, which
  3116. **            contain scheme specific parameters given
  3117. **            by server in Authenticate: fields.
  3118. **            If NULL, all scheme specifics are
  3119. **            set to NULL.
  3120. ** ON EXIT:
  3121. **    returns        a new HTAASetup node, and also adds it as
  3122. **            part of the HTAAServer given as parameter.
  3123. */
  3124. static HTAASetup *HTAASetup_new 
  3125. (HTAAServer * server, char * template, HTList * valid_schemes, HTAssocList ** scheme_specifics)
  3126. {
  3127.     HTAASetup *setup;
  3128.  
  3129.     if (!server || !template || !*template) return 0L;
  3130.  
  3131.     if (!(setup = (HTAASetup*)malloc(sizeof(HTAASetup))))
  3132.     { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "HTAASetup_new"); exit(1);};
  3133.  
  3134.     setup->retry = (BOOLEAN)0;
  3135.     setup->server = server;
  3136.     setup->template = 0L;
  3137.     if (template) HTSACopy (&(setup->template), template);
  3138.     setup->valid_schemes = valid_schemes;
  3139.     setup->scheme_specifics = scheme_specifics;
  3140.  
  3141.     HTList_addObject(server->setups, (void*)setup);
  3142.  
  3143.     return setup;
  3144. }
  3145.  
  3146.  
  3147.  
  3148. /* PRIVATE                        HTAASetup_delete()
  3149. **            FREE A HTAASetup STRUCTURE
  3150. ** ON ENTRY:
  3151. **    killme        is a pointer to the structure to free().
  3152. **
  3153. ** ON EXIT:
  3154. **    returns        nothing.
  3155. */
  3156. /* PRIVATE                    HTAASetup_updateSpecifics()
  3157. *        COPY SCHEME SPECIFIC PARAMETERS
  3158. **        TO HTAASetup STRUCTURE
  3159. ** ON ENTRY:
  3160. **    setup        destination setup structure.
  3161. **    specifics    string array containing scheme
  3162. **            specific parameters for each scheme.
  3163. **            If NULL, all the scheme specific
  3164. **            parameters are set to NULL.
  3165. **
  3166. ** ON EXIT:
  3167. **    returns        nothing.
  3168. */
  3169. static void HTAASetup_updateSpecifics 
  3170. (HTAASetup * setup, HTAssocList ** specifics)
  3171. {
  3172.     int scheme;
  3173.  
  3174.     if (setup) {
  3175.     if (setup->scheme_specifics) {
  3176.         for (scheme=0; scheme < HTAA_MAX_SCHEMES; scheme++) {
  3177.         if (setup->scheme_specifics[scheme])
  3178.             HTAssocList_delete(setup->scheme_specifics[scheme]);
  3179.         }
  3180.         free(setup->scheme_specifics);
  3181.     }
  3182.     setup->scheme_specifics = specifics;
  3183.     }
  3184. }
  3185.  
  3186.  
  3187.  
  3188.  
  3189. /*************************** HTAARealm **********************************/
  3190.  
  3191. /* PRIVATE                         HTAARealm_lookup()
  3192. **        LOOKUP HTAARealm STRUCTURE BY REALM NAME
  3193. ** ON ENTRY:
  3194. **    realm_table    a list of realm objects.
  3195. **    realmname    is the name of realm to look for.
  3196. **
  3197. ** ON EXIT:
  3198. **    returns        the realm.  NULL, if not found.
  3199. */
  3200. static HTAARealm *HTAARealm_lookup 
  3201. (HTList * realm_table,  char * realmname)
  3202. {
  3203.     if (realm_table && realmname) {
  3204.     HTList *cur = realm_table;
  3205.     HTAARealm *realm;
  3206.     
  3207.     while (0L != (realm = (HTAARealm*)(cur && (cur = cur ->next) ? cur ->object : 0L))) {
  3208.         if (0== __builtin_strcmp(realm->realmname,realmname))
  3209.         return realm;
  3210.     }
  3211.     }
  3212.     return 0L;    /* No table, NULL param, or not found */
  3213. }
  3214.  
  3215.  
  3216.  
  3217. /* PRIVATE                        HTAARealm_new()
  3218. **        CREATE A NODE CONTAINING USERNAME AND
  3219. **        PASSWORD USED FOR THE GIVEN REALM.
  3220. **        IF REALM ALREADY EXISTS, CHANGE
  3221. **        USERNAME/PASSWORD.
  3222. ** ON ENTRY:
  3223. **    realm_table    a list of realms to where to add
  3224. **            the new one, too.
  3225. **    realmname    is the name of the password domain.
  3226. **    username    and
  3227. **    password    are what you can expect them to be.
  3228. **
  3229. ** ON EXIT:
  3230. **    returns        the created realm.
  3231. */
  3232. static HTAARealm *HTAARealm_new 
  3233. (HTList * realm_table,  char * realmname,  char * username,  char * password)
  3234. {
  3235.     HTAARealm *realm;
  3236.  
  3237.     realm = HTAARealm_lookup(realm_table, realmname);
  3238.  
  3239.     if (!realm) {
  3240.     if (!(realm = (HTAARealm*)malloc(sizeof(HTAARealm))))
  3241.         { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "HTAARealm_new"); exit(1);};
  3242.     realm->realmname = 0L;
  3243.     realm->username = 0L;
  3244.     realm->password = 0L;
  3245.     HTSACopy (&(realm->realmname), realmname);
  3246.     if (realm_table) HTList_addObject(realm_table, (void*)realm);
  3247.     }
  3248.     if (username) HTSACopy (&(realm->username), username);
  3249.     if (password) HTSACopy (&(realm->password), password);
  3250.  
  3251.     return realm;
  3252. }
  3253.  
  3254.  
  3255. /* BROWSER PRIVATE                    HTAA_selectScheme()
  3256. **        SELECT THE AUTHENTICATION SCHEME TO USE
  3257. ** ON ENTRY:
  3258. **    setup    is the server setup structure which can
  3259. **        be used to make the decision about the
  3260. **        used scheme.
  3261. **
  3262. **    When new authentication methods are added to library
  3263. **    this function makes the decision about which one to
  3264. **    use at a given time.  This can be done by inspecting
  3265. **    environment variables etc.
  3266. **
  3267. **    Currently only searches for the first valid scheme,
  3268. **    and if nothing found suggests Basic scheme;
  3269. **
  3270. ** ON EXIT:
  3271. **    returns    the authentication scheme to use.
  3272. */
  3273. static HTAAScheme HTAA_selectScheme (HTAASetup * setup)
  3274. {
  3275.     HTAAScheme scheme;
  3276.  
  3277.     if (setup && setup->valid_schemes) {
  3278.     for (scheme=HTAA_BASIC; scheme < HTAA_MAX_SCHEMES; scheme++)
  3279.         if (-1 < HTList_indexOf(setup->valid_schemes, (void*)scheme))
  3280.         return scheme;
  3281.     }
  3282.     return HTAA_BASIC;
  3283. }
  3284.  
  3285.  
  3286. /***************** Basic and Pubkey Authentication ************************/
  3287.  
  3288. /* PRIVATE                        compose_auth_string()
  3289. **
  3290. **        COMPOSE Basic OR Pubkey AUTHENTICATION STRING;
  3291. **        PROMPTS FOR USERNAME AND PASSWORD IF NEEDED
  3292. **
  3293. ** ON ENTRY:
  3294. **    scheme        is either HTAA_BASIC or HTAA_PUBKEY.
  3295. **    realmname    is the password domain name.
  3296. **
  3297. ** ON EXIT:
  3298. **    returns        a newly composed authorization string,
  3299. **            (with, of course, a newly generated secret
  3300. **            key and fresh timestamp, if Pubkey-scheme
  3301. **            is being used).
  3302. ** NOTE:
  3303. **    Like throughout the entire AA package, no string or structure
  3304. **    returned by AA package needs to (or should) be freed.
  3305. **
  3306. */
  3307. static char *compose_auth_string 
  3308. (HTAAScheme scheme, HTAASetup * setup)
  3309. {
  3310.     static char *result = 0L;    /* Uuencoded presentation, the result */
  3311.     char *cleartext = 0L;    /* Cleartext presentation */
  3312.     char *ciphertext = 0L;    /* Encrypted presentation */
  3313.     int len;
  3314.     char *username;
  3315.     char *password;
  3316.     char *realmname;
  3317.     HTAARealm *realm;
  3318.     char *inet_addr = "0.0.0.0";    /* Change... @@@@ */
  3319.     char *timestamp = "42";        /* ... these @@@@ */
  3320.     
  3321.  
  3322.     if (result) {free(result); result = 0L;};    /* From previous call */
  3323.  
  3324.     if ((scheme != HTAA_BASIC && scheme != HTAA_PUBKEY) || !setup ||
  3325.     !setup->scheme_specifics || !setup->scheme_specifics[scheme] ||
  3326.     !setup->server  ||  !setup->server->realms)
  3327.     return "";
  3328.  
  3329.     realmname = HTAssocList_lookup(setup->scheme_specifics[scheme], "realm");
  3330.     if (!realmname) return "";
  3331.  
  3332.     realm = HTAARealm_lookup(setup->server->realms, realmname);
  3333.     if (!realm || setup->retry) {
  3334.     char msg[2048];
  3335.  
  3336.     if (!realm) {
  3337.         if ((WWW_TraceFlag)) fprintf((&__iob[2]), "%s `%s' %s\n",
  3338.                    "compose_auth_string: realm:", realmname,
  3339.                    "not found -- creating");
  3340.         realm = HTAARealm_new(setup->server->realms, realmname, 0L,0L);
  3341.         sprintf(msg,
  3342.             "Document is protected.\nEnter username for %s at %s: ",
  3343.             realm->realmname,
  3344.             setup->server->hostname ? setup->server->hostname : "??");
  3345.         realm->username =
  3346.         HTPrompt(msg, realm->username);
  3347.             /* Added by marca. */
  3348.             if (!realm->username)
  3349.               return "";
  3350.     }
  3351.     else {
  3352.         sprintf(msg,"Enter username for %s at %s: ", realm->realmname,
  3353.             setup->server->hostname ? setup->server->hostname : "??");
  3354.         username = HTPrompt(msg, realm->username);
  3355.         if (realm->username) {free(realm->username); realm->username = 0L;};
  3356.         realm->username = username;
  3357.             /* Added by marca. */
  3358.             if (!realm->username)
  3359.               return "";
  3360.     }
  3361.     password = HTPromptPassword("Enter password to authenticate yourself: ");
  3362.     if (realm->password) {free(realm->password); realm->password = 0L;};
  3363.     realm->password = password;
  3364.         /* Added by marca. */
  3365.         if (!realm->password)
  3366.           return "";
  3367.     }
  3368.     
  3369.     len = __builtin_strlen(realm->username ? realm->username : "") +
  3370.       __builtin_strlen(realm->password ? realm->password : "") + 3;
  3371.  
  3372.     if (scheme == HTAA_PUBKEY) {
  3373.     /* Room for secret key, timestamp and inet address */
  3374.     len += __builtin_strlen(secret_key ? secret_key : "") + 30;
  3375.     }
  3376.     else
  3377.     if (secret_key) {free(secret_key); secret_key = 0L;};
  3378.  
  3379.     if (!(cleartext  = (char*)calloc(len, 1)))
  3380.     { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "compose_auth_string"); exit(1);};
  3381.  
  3382.     if (realm->username) __builtin_strcpy(cleartext,realm->username);
  3383.     else *cleartext = (char)0;
  3384.  
  3385.     strcat(cleartext, ":");
  3386.  
  3387.     if (realm->password) strcat(cleartext, realm->password);
  3388.  
  3389.     if (scheme == HTAA_PUBKEY) {
  3390.     strcat(cleartext, ":");
  3391.     strcat(cleartext, inet_addr);
  3392.     strcat(cleartext, ":");
  3393.     strcat(cleartext, timestamp);
  3394.     strcat(cleartext, ":");
  3395.     if (secret_key) strcat(cleartext, secret_key);
  3396.  
  3397.     if (!((ciphertext = (char*)malloc(2*len)) &&
  3398.           (result     = (char*)malloc(3*len))))
  3399.         { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "compose_auth_string"); exit(1);};
  3400.     free(cleartext);
  3401.     free(ciphertext);
  3402.     }
  3403.     else { /* scheme == HTAA_BASIC */
  3404.       /* Added "+ 1" marca. */
  3405.         /* Ari fix. */
  3406.     if (!(result = (char*)malloc(4 * ((len+2)/3) + 1)))
  3407.         { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "compose_auth_string"); exit(1);};
  3408.         /* Added cast to unsigned char * on advice of
  3409.            erik@sockdev.uni-c.dk (Erik Bertelsen). */
  3410.     HTUU_encode((unsigned char *)cleartext, __builtin_strlen(cleartext), result);
  3411.     free(cleartext);
  3412.     }
  3413.     if((WWW_TraceFlag)) fprintf((&__iob[2]),"sending auth line: %s\n",result);
  3414.     return result;
  3415. }
  3416.  
  3417.  
  3418.  
  3419.  
  3420. /* BROWSER PUBLIC                    HTAA_composeAuth()
  3421. **
  3422. **    SELECT THE AUTHENTICATION SCHEME AND
  3423. **    COMPOSE THE ENTIRE AUTHORIZATION HEADER LINE
  3424. **    IF WE ALREADY KNOW THAT THE HOST REQUIRES AUTHENTICATION
  3425. **
  3426. ** ON ENTRY:
  3427. **    hostname    is the hostname of the server.
  3428. **    portnumber    is the portnumber in which the server runs.
  3429. **    docname        is the pathname of the document (as in URL)
  3430. **
  3431. ** ON EXIT:
  3432. **    returns    NULL, if no authorization seems to be needed, or
  3433. **        if it is the entire Authorization: line, e.g.
  3434. **
  3435. **           "Authorization: Basic username:password"
  3436. **
  3437. **        As usual, this string is automatically freed.
  3438. */
  3439.  char *HTAA_composeAuth 
  3440. ( char * hostname,  int portnumber,  char * docname)
  3441. {
  3442.     static char *result = 0L;
  3443.     char *auth_string;
  3444.     BOOLEAN retry;
  3445.     HTAAScheme scheme;
  3446.  
  3447.     if (result) {free(result); result = 0L;};            /* From previous call */
  3448.  
  3449.     if ((WWW_TraceFlag))
  3450.     fprintf((&__iob[2]), 
  3451.         "Composing Authorization for %s:%d/%s\n",
  3452.         hostname, portnumber, docname);
  3453.  
  3454.     if (current_portnumber != portnumber ||
  3455.     !current_hostname || !current_docname ||
  3456.     !hostname         || !docname         ||
  3457.     0 != __builtin_strcmp(current_hostname,hostname) ||
  3458.     0 != __builtin_strcmp(current_docname,docname)) {
  3459.  
  3460.     retry = (BOOLEAN)0;
  3461.  
  3462.     current_portnumber = portnumber;
  3463.     
  3464.     if (hostname) HTSACopy (&(current_hostname), hostname);
  3465.     else if (current_hostname) {free(current_hostname); current_hostname = 0L;};
  3466.  
  3467.     if (docname) HTSACopy (&(current_docname), docname);
  3468.     else if (current_docname) {free(current_docname); current_docname = 0L;};
  3469.     }
  3470.     else retry = (BOOLEAN)1;
  3471.     
  3472.     if (!current_setup || !retry)
  3473.     current_setup = HTAASetup_lookup(hostname, portnumber, docname);
  3474.  
  3475.     if (!current_setup)
  3476.     return 0L;
  3477.  
  3478.  
  3479.     switch (scheme = HTAA_selectScheme(current_setup)) {
  3480.       case HTAA_BASIC:
  3481.       case HTAA_PUBKEY:
  3482.     auth_string = compose_auth_string(scheme, current_setup);
  3483.     break;
  3484.       case HTAA_KERBEROS_V4:
  3485.     /* OTHER AUTHENTICATION ROUTINES ARE CALLED HERE */
  3486.       default:
  3487.     {
  3488.         char msg[2048];
  3489.         sprintf(msg, "%s %s `%s'",
  3490.             "This client doesn't know how to compose authentication",
  3491.             "information for scheme", HTAAScheme_name(scheme));
  3492.         HTAlert(msg);
  3493.         auth_string = 0L;
  3494.     }
  3495.     } /* switch scheme */
  3496.  
  3497.     current_setup->retry = (BOOLEAN)0;
  3498.  
  3499.     /* Added by marca. */
  3500.     if (!auth_string)
  3501.       return 0L;
  3502.  
  3503.     if (!(result = (char*)malloc(sizeof(char) * (__builtin_strlen(auth_string)+40))))
  3504.     { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "HTAA_composeAuth"); exit(1);};
  3505.     __builtin_strcpy(result,"Authorization: ");
  3506.     strcat(result, HTAAScheme_name(scheme));
  3507.     strcat(result, " ");
  3508.     strcat(result, auth_string);
  3509.     return result;
  3510. }
  3511.  
  3512.  
  3513.  
  3514.         
  3515. /* BROWSER PUBLIC                HTAA_shouldRetryWithAuth()
  3516. **
  3517. **        DETERMINES IF WE SHOULD RETRY THE SERVER
  3518. **        WITH AUTHORIZATION
  3519. **        (OR IF ALREADY RETRIED, WITH A DIFFERENT
  3520. **        USERNAME AND/OR PASSWORD (IF MISSPELLED))
  3521. ** ON ENTRY:
  3522. **    start_of_headers is the first block already read from socket,
  3523. **            but status line skipped; i.e. points to the
  3524. **            start of the header section.
  3525. **    length        is the remaining length of the first block.
  3526. **    soc        is the socket to read the rest of server reply.
  3527. **
  3528. **            This function should only be called when
  3529. **            server has replied with a 401 (Unauthorized)
  3530. **            status code.
  3531. ** ON EXIT:
  3532. **    returns        YES, if connection should be retried.
  3533. **                 The node containing all the necessary
  3534. **                 information is
  3535. **                * either constructed if it does not exist
  3536. **                * or password is reset to NULL to indicate
  3537. **                  that username and password should be
  3538. **                  reprompted when composing Authorization:
  3539. **                  field (in function HTAA_composeAuth()).
  3540. **            NO, otherwise.
  3541. */
  3542.  BOOLEAN HTAA_shouldRetryWithAuth 
  3543. (char * start_of_headers, int length, int soc)
  3544. {
  3545.     HTAAScheme scheme;
  3546.     char *line;
  3547.     int num_schemes = 0;
  3548.     HTList *valid_schemes = HTList_new();
  3549.     HTAssocList **scheme_specifics = 0L;
  3550.     char *template = 0L;
  3551.  
  3552.  
  3553.     /* Read server reply header lines */
  3554.  
  3555.     if ((WWW_TraceFlag))
  3556.     fprintf((&__iob[2]), "Server reply header lines:\n");
  3557.  
  3558.     HTAA_setupReader(start_of_headers, length, soc);
  3559.     while (0L != (line = HTAA_getUnfoldedLine())  &&  *line != (char)0) {
  3560.  
  3561.     if ((WWW_TraceFlag)) fprintf((&__iob[2]), "%s\n", line);
  3562.  
  3563.     if (strchr(line, ':')) {    /* Valid header line */
  3564.  
  3565.         char *p = line;
  3566.         char *fieldname = HTNextField(&p);
  3567.         char *arg1 = HTNextField(&p);
  3568.         char *args = p;
  3569.         
  3570.         if (0==strcasecomp(fieldname, "WWW-Authenticate:")) {
  3571.         if (HTAA_UNKNOWN != (scheme = HTAAScheme_enum(arg1))) {
  3572.             HTList_addObject(valid_schemes, (void*)scheme);
  3573.             if (!scheme_specifics) {
  3574.             int i;
  3575.             scheme_specifics = (HTAssocList**)
  3576.                 malloc(HTAA_MAX_SCHEMES * sizeof(HTAssocList*));
  3577.             if (!scheme_specifics)
  3578.                 { fprintf((&__iob[2]), "%s %s: out of memory.\nProgram aborted.\n", "HTAABrow.c", "HTAA_shouldRetryWithAuth"); exit(1);};
  3579.             for (i=0; i < HTAA_MAX_SCHEMES; i++)
  3580.                 scheme_specifics[i] = 0L;
  3581.             }
  3582.             scheme_specifics[scheme] = HTAA_parseArgList(args);
  3583.             num_schemes++;
  3584.         }
  3585.         else if ((WWW_TraceFlag)) {
  3586.             fprintf((&__iob[2]), "Unknown scheme `%s' %s\n",
  3587.                 (arg1 ? arg1 : "(null)"),
  3588.                 "in WWW-Authenticate: field");
  3589.         }
  3590.         }
  3591.  
  3592.         else if (0==strcasecomp(fieldname, "WWW-Protection-Template:")) {
  3593.         if ((WWW_TraceFlag))
  3594.             fprintf((&__iob[2]), "Protection template set to `%s'\n", arg1);
  3595.         HTSACopy (&(template), arg1);
  3596.         }
  3597.  
  3598.     } /* if a valid header line */
  3599.     else if ((WWW_TraceFlag)) {
  3600.         fprintf((&__iob[2]), "Invalid header line `%s' ignored\n", line);
  3601.     } /* else invalid header line */
  3602.     } /* while header lines remain */
  3603.  
  3604.  
  3605.     /* So should we retry with authorization */
  3606.  
  3607.     if (num_schemes == 0) {        /* No authentication valid */
  3608.     current_setup = 0L;
  3609.     return (BOOLEAN)0;
  3610.     }
  3611.  
  3612.     if (current_setup && current_setup->server) {
  3613.     /* So we have already tried with authorization.    */
  3614.     /* Either we don't have access or username or    */
  3615.     /* password was misspelled.            */
  3616.         
  3617.     /* Update scheme-specific parameters    */
  3618.     /* (in case they have expired by chance).    */
  3619.     HTAASetup_updateSpecifics(current_setup, scheme_specifics);
  3620.  
  3621.     if ((BOOLEAN)0 == HTConfirm("Authorization failed.  Retry?")) {
  3622.         current_setup = 0L;
  3623.         return (BOOLEAN)0;
  3624.     } /* HTConfirm(...) == NO */
  3625.     else { /* re-ask username+password (if misspelled) */
  3626.         current_setup->retry = (BOOLEAN)1;
  3627.         return (BOOLEAN)1;
  3628.     } /* HTConfirm(...) == YES */
  3629.     } /* if current_setup != NULL */
  3630.  
  3631.     else { /* current_setup == NULL, i.e. we have a     */
  3632.        /* first connection to a protected server or  */
  3633.        /* the server serves a wider set of documents */
  3634.        /* than we expected so far.                   */
  3635.  
  3636.     HTAAServer *server = HTAAServer_lookup(current_hostname,
  3637.                            current_portnumber);
  3638.     if (!server) {
  3639.         server = HTAAServer_new(current_hostname,
  3640.                     current_portnumber);
  3641.     }
  3642.     if (!template)
  3643.         template = HTAA_makeProtectionTemplate(current_docname);
  3644.     current_setup = HTAASetup_new(server, 
  3645.                       template,
  3646.                       valid_schemes,
  3647.                       scheme_specifics);
  3648.  
  3649.         HTAlert("Access without authorization denied -- retrying");
  3650.     return (BOOLEAN)1;
  3651.     } /* else current_setup == NULL */
  3652.  
  3653.     /* Never reached */
  3654. }
  3655.  
  3656.  
  3657.  
  3658.